Show
Ignore:
Timestamp:
08/26/06 23:39:31 (18 years ago)
Author:
jerome
Message:

Refactored some duplicate code.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • pkpgcounter/trunk/pkpgpdls/pdf.py

    r364 r371  
    2525 
    2626import sys 
    27 import popen2 
    2827import re 
    2928 
     
    4443class Parser(pdlparser.PDLParser) : 
    4544    """A parser for PDF documents.""" 
     45    totiffcommand = 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 
    4646    def isValid(self) :     
    4747        """Returns 1 if data is PDF, else 0.""" 
     
    105105        return pagecount     
    106106         
    107     def convertToTiffMultiPage24NC(self, fname, dpi) : 
    108         """Converts the input file to TIFF format, X dpi, 24 bits per pixel, uncompressed. 
    109            Writes TIFF datas to the outputfile file object. 
    110         """    
    111         command = 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%i -sOutputFile="%s" -' % (dpi, fname) 
    112         child = popen2.Popen4(command) 
    113         try : 
    114             data = self.infile.read(pdlparser.MEGABYTE)     
    115             while data : 
    116                 child.tochild.write(data) 
    117                 data = self.infile.read(pdlparser.MEGABYTE) 
    118             child.tochild.flush() 
    119             child.tochild.close()     
    120         except (IOError, OSError), msg :     
    121             raise pdlparser.PDLParserError, "Problem during conversion to TIFF : %s" % msg 
    122              
    123         child.fromchild.close() 
    124         try : 
    125             child.wait() 
    126         except OSError, msg :     
    127             raise pdlparser.PDLParserError, "Problem during conversion to TIFF : %s" % msg 
    128          
    129107def test() :         
    130108    """Test function."""