Changeset 371
- Timestamp:
- 08/26/06 23:39:31 (18 years ago)
- Location:
- pkpgcounter/trunk/pkpgpdls
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pdf.py
r364 r371 25 25 26 26 import sys 27 import popen228 27 import re 29 28 … … 44 43 class Parser(pdlparser.PDLParser) : 45 44 """A parser for PDF documents.""" 45 totiffcommand = 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 46 46 def isValid(self) : 47 47 """Returns 1 if data is PDF, else 0.""" … … 105 105 return pagecount 106 106 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" % msg122 123 child.fromchild.close()124 try :125 child.wait()126 except OSError, msg :127 raise pdlparser.PDLParserError, "Problem during conversion to TIFF : %s" % msg128 129 107 def test() : 130 108 """Test function.""" -
pkpgcounter/trunk/pkpgpdls/pdlparser.py
r363 r371 23 23 24 24 import sys 25 import popen2 25 26 26 27 KILOBYTE = 1024 … … 40 41 class PDLParser : 41 42 """Generic PDL parser.""" 43 totiffcommand = None # Default command to convert to TIFF 42 44 def __init__(self, infile, debug=0, firstblock=None, lastblock=None) : 43 45 """Initialize the generic parser.""" … … 87 89 Writes TIFF datas to the file named by fname. 88 90 """ 89 raise RuntimeError, "Not implemented !" 91 if self.totiffcommand : 92 child = popen2.Popen4(self.totiffcommand % locals()) 93 try : 94 try : 95 data = self.infile.read(MEGABYTE) 96 while data : 97 child.tochild.write(data) 98 data = self.infile.read(MEGABYTE) 99 child.tochild.flush() 100 child.tochild.close() 101 except (IOError, OSError), msg : 102 raise PDLParserError, "Problem during conversion to TIFF : %s" % msg 103 finally : 104 child.fromchild.close() 105 106 try : 107 child.wait() 108 except OSError, msg : 109 raise PDLParserError, "Problem during conversion to TIFF : %s" % msg 110 else : 111 raise PDLParserError, "Impossible to compute ink coverage for this file format." -
pkpgcounter/trunk/pkpgpdls/postscript.py
r363 r371 34 34 class Parser(pdlparser.PDLParser) : 35 35 """A parser for PostScript documents.""" 36 totiffcommand = 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' 36 37 def isValid(self) : 37 38 """Returns 1 if data is PostScript, else 0.""" … … 177 178 return self.natively() or self.throughGhostScript() 178 179 179 def convertToTiffMultiPage24NC(self, fname, dpi) :180 """Converts the input file to TIFF format, X dpi, 24 bits per pixel, uncompressed.181 Writes TIFF datas to the outputfile file object.182 """183 command = 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%i -sOutputFile="%s" -' % (dpi, fname)184 child = popen2.Popen4(command)185 try :186 data = self.infile.read(pdlparser.MEGABYTE)187 while data :188 child.tochild.write(data)189 data = self.infile.read(pdlparser.MEGABYTE)190 child.tochild.flush()191 child.tochild.close()192 except (IOError, OSError), msg :193 raise pdlparser.PDLParserError, "Problem during conversion to TIFF : %s" % msg194 195 child.fromchild.close()196 try :197 child.wait()198 except OSError, msg :199 raise pdlparser.PDLParserError, "Problem during conversion to TIFF : %s" % msg200 201 180 def test() : 202 181 """Test function."""