Changeset 491 for pkpgcounter/trunk/pkpgpdls/pdf.py
- Timestamp:
- 11/20/07 00:04:09 (17 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pdf.py
r463 r491 23 23 """This modules implements a page counter for PDF documents.""" 24 24 25 import sys26 25 import re 27 26 … … 34 33 self.major = major 35 34 self.minor = minor 35 self.majori = int(major) 36 self.minori = int(minor) 36 37 self.description = description 37 38 self.comments = [] … … 43 44 """A parser for PDF documents.""" 44 45 totiffcommands = [ 'gs -sDEVICE=tiff24nc -dPARANOIDSAFER -dNOPAUSE -dBATCH -dQUIET -r%(dpi)i -sOutputFile="%(fname)s" -' ] 46 openmode = "rU" 45 47 def isValid(self) : 46 48 """Returns True if data is PDF, else False.""" … … 62 64 objre = re.compile(r"\s?(\d+)\s+(\d+)\s+obj[<\s/]?") 63 65 for line in self.infile : 64 line = line.strip() 66 line = line.strip() 65 67 if line.startswith("% ") : 66 68 if inobject : … … 72 74 result = objre.search(line) 73 75 if result is not None : 74 (major, minor) = [int(num) for num in line[result.start():result.end()].split()[:2]]76 (major, minor) = line[result.start():result.end()].split()[:2] 75 77 obj = PDFObject(major, minor, lastcomment) 76 78 obj.content.append(line[result.end():]) … … 86 88 # if we want the first one, just use > instead of >= 87 89 oldobject = objects.setdefault(major, obj) 88 if minor >= oldobject.minor:90 if int(minor) >= oldobject.minori : 89 91 objects[major] = obj 92 # self.logdebug("Object(%i, %i) overwritten with Object(%i, %i)" % (oldobject.majori, oldobject.minori, obj.majori, obj.minori)) 93 # self.logdebug("Object(%i, %i)" % (obj.majori, obj.minori)) 90 94 inobject = 0 91 95 else : … … 94 98 95 99 # Now we check each PDF object we've just created. 96 # colorregexp = re.compile(r"(/ColorSpace) ?(/DeviceRGB|/DeviceCMYK)[/ \t\r\n]", re.I)97 100 newpageregexp = re.compile(r"(/Type)\s?(/Page)[/>\s]", re.I) 98 101 pagecount = 0 … … 103 106 pagecount += count 104 107 return pagecount 105 106 if __name__ == "__main__" :107 pdlparser.test(Parser)