PDF count pages

davidb at mcs.st-and.ac.uk davidb at mcs.st-and.ac.uk
Tue Dec 7 23:12:01 CET 2004


Andreas Lobinger wrote:
>
> Jose Benito Gonzalez Lopez wrote:
> > Does anyone know how I could do in order
> > to get/count the number of pages of a PDF file?
>
> Like this ?
[...]
>  >>> import pdffile
>  >>> pf = pdffile.pdffile('../rfc1950.pdf')
>  >>> import pages
>  >>> pp = pages.pages(pf)
>  >>> len(pp.pagelist)
[...]

That's interesting. Here's my equivalent example:

Python 2.3.3 (#1, May  2 2004, 15:04:07)
[GCC 3.2.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from pdftools import pdffile
>>> doc = pdffile.PDFDocument("PDFSPEC.pdf")
>>> doc.count_pages()
518

The API shown above is from an unreleased version of pdftools
(http://www.boddie.org.uk/david/Projects/Python/pdftools/).

> This is an example of the usage of pdfplayground. pdfplayground
> is available via sourceforge. There is no package at the
> moment, but you should be able to check out via anon-cvs.

I browsed the code in CVS and it looks like a pretty comprehensive
implementation. Maybe we should join forces.

David




More information about the Python-list mailing list