ocrmypdf/OCRmyPDF · error · InputFileError

pdfminer could not process page {pageno} (counting from 0).

Error message

pdfminer could not process page {pageno} (counting from 0).

What it means

Raised when pdfminer.six's PDFPage.get_pages() yields no page object for the requested zero-based page number. This indicates the PDF's internal structure prevented pdfminer from producing a page object even though the page number was requested.

Source

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

) -> LTPage | None:
    """Get the page analysis for a given page."""
    rman = pdfminer.pdfinterp.PDFResourceManager(caching=True)
    disable_boxes_flow = None
    dev = TextPositionTracker(
        rman,
        laparams=LAParams(
            all_texts=True, detect_vertical=True, boxes_flow=disable_boxes_flow
        ),
    )
    interp = pdfminer.pdfinterp.PDFPageInterpreter(rman, dev)

    with patch_pdfminer(pscript5_mode):
        try:
            with Path(infile).open('rb') as f:
                page_iter = PDFPage.get_pages(f, pagenos=[pageno], maxpages=0)
                page = next(page_iter, None)
                if page is None:
                    raise InputFileError(
                        f"pdfminer could not process page {pageno} (counting from 0)."
                    )
                interp.process_page(page)
        except PDFTextExtractionNotAllowed as e:
            raise EncryptedPdfError() from e

    return dev.get_result()


class PdfMinerState:
    """Provide a context manager for using pdfminer.six.

    This ensures that the file is closed. It also provides a cache of pages
    from the PDF so that they can be reused if needed, to improve performance.
    """

    def __init__(self, infile: Path, pscript5_mode: bool) -> None:
        """Initialize the context manager.

View on GitHub (pinned to 5074a0b0e1)

Solutions

  1. Validate the PDF first with a tool like qpdf --check or pikepdf open and repair the input
  2. Ensure pageno is within the page range reported by PdfInfo for the same file
  3. If the PDF is corrupt, run OCRmyPDF with input file repair or preprocess with qpdf --linearize / pikepdf
  4. Check the file isn't being modified concurrently during processing

Example fix

import pikepdf
try:
    with pikepdf.open(path):
        pass
except pikepdf.PdfError:
    repaired = path.with_suffix('.repaired.pdf')
    pikepdf.open(path).save(repaired)
    path = repaired
# now run get_page_analysis(path, pageno)
Defensive patterns

Strategy: validation

Validate before calling

import pikepdf
try:
    with pikepdf.open(path) as pdf:
        n = len(pdf.pages)
    assert 0 <= pageno < n
except pikepdf.PdfError:
    raise ValueError('input PDF is corrupt; repair before analysis')

Try / catch

try:\n    analysis = get_page_analysis(path, pageno)\nexcept InputFileError as e:\n    logger.warning('page %d unparseable: %s', pageno, e)\n    analysis = None

Prevention

When it happens

Trigger: Calling get_page_analysis(infile, pageno) where pdfminer returns None for next(page_iter) — e.g. a truncated or malformed page tree, or pageno beyond the actual page count of the file as seen by pdfminer.

Common situations: Processing corrupt/truncated PDFs, PDFs with broken xref tables, or a race where the file was modified between page count discovery and per-page analysis.

Related errors


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