I am using pikepdf to open a pdf file and get the page count for that file. My code is roughly:
import pikepdf
with open(file_uri, "rb") as input_pdf:
input_reader = pikepdf.Pdf.open(input_pdf)
page_count: int = len(input_reader.pages)
Very rarely a pdf file will give the incorrect number of pages. For example, I have a file that when opened on my laptop in a PDF viewer is 39 pages. pikepdf gives a page count of 47 pages. The metadata when I click Get Info in the file browser states 39 pages.
Unfortunately, I cannot share the file as it has protected information.
How would I make sure I get the correct page count from pikepdf? I've used other Python PDF libraries (eg pypdf) in the past but they have errors opening python files sometimes.