|
Description:
A simple way to count the pages of a PDF the pure Python way.
Source: Text Source
import re
rxcountpages = re.compile(r"$\s*/Type\s*/Page[/\s]", re.MULTILINE|re.DOTALL)
def countPages(filename):
data = file(filename,"rb").read()
return len(rxcountpages.findall(data))
if __name__=="__main__":
print "Number of pages in PDF File:", countPages("test.pdf")
Discussion:
Very straight forward approach. To do more counting and manipulation with PDF have a look at pyPDF (http://pybrary.net/pyPdf).
|