Logo Search packages:      
Sourcecode: khmerconverter version File versions  Download package

def khmerconverter v.1.4::modules::legacyConvertOdt::legacyConvertOdt::convertOdtFile (   self,
  inputFileName,
  outputFileName,
  outputFont,
  outputFontSize = None 
)
This function converts OpenOffice.org Writer file.
inputFileName : name of input file to convert
outputFileName : name of output file. Default value is converted-inputFileName.
outputFont : legacy output font name. Default depends on the font type.
outputFontSize : force the font size the output file will use. value = None to ignore.

Definition at line 49 of file legacyConvertOdt.py.

                                                                                              :
        """This function converts OpenOffice.org Writer file.
        inputFileName : name of input file to convert
        outputFileName : name of output file. Default value is converted-inputFileName.
        outputFont : legacy output font name. Default depends on the font type.
        outputFontSize : force the font size the output file will use. value = None to ignore.
        """
        if (not self.fd.isConvertable(outputFont)):
            raise TypeError('unknown output font ' + outputFont + '!')
    
        if (inputFileName == outputFileName):
            raise TypeError('input file and output file must be different!')
    
        try:
            # read zip file (.odt)
            zipIn = zipfile.ZipFile(inputFileName, "r")
        except IOError:
            raise IOError('Cannot open file "' +  inputFileName + '" for reading!')
    
        if (not (self.CONTENTXML and self.STYLESXML) in zipIn.namelist()):        
            raise TypeError('Input file' + inputFileName + 'is not an odt file!')
    
        try:
            # create new zip file (.odt)
            zipOut = zipfile.ZipFile(outputFileName, "w", DEFLATED)
        except IOError:               
            raise IOError('Cannot open file "' +  outputFileName + '" for writing!')
        
        # get data for the font
        self.outputFont = self.fd.defaultFont(outputFont)
        self.data = self.fd.unicodeData(self.outputFont)
        if (outputFontSize):
            self.outputFontSize = str(outputFontSize) + 'pt'
        
        for file in zipIn.namelist():
            fdata = zipIn.read(file)
            # do the converting for content.xml only
            if (file == self.CONTENTXML):
                fdata = self.processContent(fdata)
                # TODO: do we need to test the type? When do we not want to encode in UTF-8 ?
                if (type(fdata) == unicode):
                    fdata = fdata.encode('utf-8')
            elif (file == self.STYLESXML):
                fdata = self.processStyle(fdata)
                # TODO: do we need to test the type? When do we not want to encode in UTF-8 ?
                if (type(fdata) == unicode):
                    fdata = fdata.encode('utf-8')
            zipOut.writestr(file, fdata)
        zipOut.close()
        zipIn.close()
    

Generated by  Doxygen 1.6.0   Back to index