DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Count PDF Pages

06.21.2011
| 8502 views |
  • submit to reddit
        Returns the number of pages in a PDF file

import re

def count_pdf_pages(path):
	pattern = re.compile("<<.*?Page.*?>>", re.MULTILINE)
	file = open(path, 'rb')
	content = f.read()
	file .close()
	return len(pattern.findall(content))