Skip to content

Instantly share code, notes, and snippets.

@miodeqqq
Created September 10, 2019 12:55
Show Gist options
  • Select an option

  • Save miodeqqq/0a06c395b21cec60a7e0d8abe7a0793f to your computer and use it in GitHub Desktop.

Select an option

Save miodeqqq/0a06c395b21cec60a7e0d8abe7a0793f to your computer and use it in GitHub Desktop.
Retrieve number of pages from PDF using pdfminer
from pdfminer.pdfdocument import PDFDocument
from pdfminer.pdfparser import PDFParser
from pdfminer.pdftypes import resolve1
with open('/path/to/file.pdf', 'rb') as f:
parser = PDFParser(f)
doc = PDFDocument(parser)
parser.set_document(doc)
pages = resolve1(doc.catalog['Pages')
pages_count = pages.get('Count', 0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment