[reportlab-users] Number of pages in a pdf file
Wed, 11 Jun 2003 14:07:17 +0200
> *given that the files are always
> created using Reportlab*, is there a relatively simply and reliable way
> extract this information?
The best way I can find is to look for lines of the form:
'PageXX' '<reportlab.pdfbase.pdfdoc.PDFPage instance '
pageNumberRegexp = re.compile("% 'Page([0-9]+)'.+PDFPage ")
file = open(fileName)
for line in file:
match = pageNumberRegexp.match(line)
pageNumber = match.group(1)
You could also take the /Count value of the "page tree",
but it is not as easy to parse.
Amaury Forgeot d'Arc