Changeset 355 for pkpgcounter/trunk/pkpgpdls/pdf.py
- Timestamp:
- 08/14/06 01:00:18 (18 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
pkpgcounter/trunk/pkpgpdls/pdf.py
r303 r355 21 21 # $Id$ 22 22 # 23 24 """This modules implements a page counter for PDF documents.""" 23 25 24 26 import sys … … 58 60 objects = {} 59 61 inobject = 0 60 # objre = re.compile(r"\s*(\d+)\s+(\d+)\s+obj[<\s/]*")61 62 objre = re.compile(r"\s?(\d+)\s+(\d+)\s+obj[<\s/]?") 62 63 for fullline in self.infile.xreadlines() : … … 72 73 result = objre.search(line) 73 74 if result is not None : 74 (major, minor) = map(int, line[result.start():result.end()].split()[:2])75 (major, minor) = [int(num) for num in line[result.start():result.end()].split()[:2]] 75 76 obj = PDFObject(major, minor, lastcomment) 76 77 obj.content.append(line[result.end():]) … … 94 95 95 96 # Now we check each PDF object we've just created. 96 self.iscolor = None97 # colorregexp = re.compile(r"(/ColorSpace) ?(/DeviceRGB|/DeviceCMYK)[/ \t\r\n]", re.I) 97 98 newpageregexp = re.compile(r"(/Type)\s?(/Page)[/\s]", re.I) 98 colorregexp = re.compile(r"(/ColorSpace) ?(/DeviceRGB|/DeviceCMYK)[/ \t\r\n]", re.I)99 99 pagecount = 0 100 100 for obj in objects.values() : … … 102 102 count = len(newpageregexp.findall(content)) 103 103 pagecount += count 104 if colorregexp.match(content) :105 self.iscolor = 1106 self.logdebug("ColorSpace : %s" % content)107 104 return pagecount 108 105