ocrmypdf/OCRmyPDF · error · InputFileError

pdfminer did not find page {pageno} in the input file.

Error message

pdfminer did not find page {pageno} in the input file.

What it means

Raised when the page iterator is exhausted before reaching the requested page number — pdfminer simply did not find that page in the input file. This means the requested pageno exceeds the pages pdfminer can iterate.

Source

Thrown at src/ocrmypdf/pdfinfo/layout.py:364

        """Enter the context manager."""
        self.file = Path(self.infile).open('rb')
        self.page_iter = PDFPage.get_pages(self.file)
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        """Exit the context manager."""
        if self.file:
            self.file.close()
        return True

    def get_page_analysis(self, pageno: int):
        """Get the page analysis for a given page."""
        assert self.page_iter is not None, "must be used as a context manager"
        while len(self.page_cache) <= pageno:
            try:
                self.page_cache.append(next(self.page_iter))
            except StopIteration:
                raise InputFileError(
                    f"pdfminer did not find page {pageno} in the input file."
                ) from None
        page = self.page_cache[pageno]
        if not page:
            raise InputFileError(
                f"pdfminer could not process page {pageno} (counting from 0)."
            )
        dev = TextPositionTracker(
            self.rman,
            laparams=LAParams(
                all_texts=True, detect_vertical=True, boxes_flow=self.disable_boxes_flow
            ),
        )
        interp = pdfminer.pdfinterp.PDFPageInterpreter(self.rman, dev)

        with patch_pdfminer(self.pscript5_mode):
            interp.process_page(page)

View on GitHub (pinned to 5074a0b0e1)

Solutions

  1. Check pageno against the PdfInfo page count for the same file before calling
  2. If counts differ between pikepdf and pdfminer, repair the PDF (qpdf --check / pikepdf)
  3. Verify your loop uses the same zero-based indexing assumption as the library
  4. Reopen a fresh analysis context if the underlying file changed

Example fix

// before
for i in range(info.page_count_pdf)
    analysis = cache.get_page_analysis(i)  # may raise if pdfminer yields fewer
// after
info = PdfInfo.from_path(path)
n = min(info.page_count_pdf, info.page_count_pdfminer)
for i in range(n):
    analysis = cache.get_page_analysis(i)
Defensive patterns

Strategy: validation

Validate before calling

info = PdfInfo.from_path(path)
if pageno >= info.page_count_pdf:
    raise IndexError(f'pageno {pageno} out of range (0..{info.page_count_pdf-1})')

Try / catch

try:\n    analysis = cache.get_page_analysis(pageno)\nexcept InputFileError:\n    analysis = None  # skip missing page

Prevention

When it happens

Trigger: Calling get_page_analysis(pageno) on a PageAnalysisCache with a pageno >= the number of pages pdfminer actually yields (StopIteration while filling page_cache).

Common situations: Mismatch between the page count reported by another parser (pikepdf) and pdfminer — e.g. a damaged page tree where pdfminer stops early — or off-by-one indexing bugs in caller code.

Related errors


AI-assisted analysis of ocrmypdf/OCRmyPDF@5074a0b0e1 (2026-08-27). Data as JSON: /api/errors/20c93ed44248d8d3. Report an issue: GitHub.