Changeset 1622 for pykota/trunk/pykota/pdlanalyzer.py
- Timestamp:
- 07/22/04 15:49:51 (20 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pykota/trunk/pykota/pdlanalyzer.py
r1599 r1622 22 22 # 23 23 # $Log$ 24 # Revision 1.26 2004/07/22 13:49:51 jalet 25 # Added support for binary PostScript through GhostScript if native DSC 26 # compliant PostScript analyzer doesn't find any page. This is much 27 # slower though, so native analyzer is tried first. 28 # 24 29 # Revision 1.25 2004/07/10 14:06:36 jalet 25 30 # Fix for Python2.1 incompatibilities … … 108 113 import tempfile 109 114 import mmap 115 import popen2 110 116 111 117 KILOBYTE = 1024 … … 125 131 """Initialize PostScript Analyzer.""" 126 132 self.infile = infile 127 128 def getJobSize(self) : 133 134 def throughGhostScript(self) : 135 """Get the count through GhostScript, useful for non-DSC compliant PS files.""" 136 self.infile.seek(0) 137 command = 'gs -sDEVICE=bbox -dNOPAUSE -dBATCH -dQUIET - 2>&1 | grep -c "%%HiResBoundingBox:" 2>/dev/null' 138 child = popen2.Popen4(command) 139 try : 140 data = self.infile.read(MEGABYTE) 141 while data : 142 child.tochild.write(data) 143 data = self.infile.read(MEGABYTE) 144 child.tochild.flush() 145 child.tochild.close() 146 except (IOError, OSError), msg : 147 raise PDLAnalyzerError, "Problem during analysis of Binary PostScript document." 148 149 pagecount = 0 150 try : 151 pagecount = int(child.fromchild.readline().strip()) 152 except (IOError, OSError, AttributeError, ValueError) : 153 raise PDLAnalyzerError, "Problem during analysis of Binary PostScript document." 154 child.fromchild.close() 155 156 try : 157 retcode = child.wait() 158 except OSError, msg : 159 raise PDLAnalyzerError, "Problem during analysis of Binary PostScript document." 160 return pagecount 161 162 def natively(self) : 129 163 """Count pages in a DSC compliant PostScript document.""" 164 self.infile.seek(0) 130 165 pagecount = 0 131 166 for line in self.infile.xreadlines() : … … 133 168 pagecount += 1 134 169 return pagecount 170 171 def getJobSize(self) : 172 """Count pages in PostScript document.""" 173 return self.natively() or self.throughGhostScript() 135 174 136 175 class PDFAnalyzer :