{"record":{"id":"7bdb1ef5dd8c0d98","repo":"ocrmypdf/OCRmyPDF","slug":"pdfminer-could-not-process-page-pageno-counting","errorCode":null,"errorMessage":"pdfminer could not process page {pageno} (counting from 0).","messagePattern":"pdfminer could not process page (.+?) \\(counting from 0\\)\\.","errorType":"exception","errorClass":"InputFileError","httpStatus":null,"severity":"error","filePath":"src/ocrmypdf/pdfinfo/layout.py","lineNumber":313,"sourceCode":") -> LTPage | None:\n    \"\"\"Get the page analysis for a given page.\"\"\"\n    rman = pdfminer.pdfinterp.PDFResourceManager(caching=True)\n    disable_boxes_flow = None\n    dev = TextPositionTracker(\n        rman,\n        laparams=LAParams(\n            all_texts=True, detect_vertical=True, boxes_flow=disable_boxes_flow\n        ),\n    )\n    interp = pdfminer.pdfinterp.PDFPageInterpreter(rman, dev)\n\n    with patch_pdfminer(pscript5_mode):\n        try:\n            with Path(infile).open('rb') as f:\n                page_iter = PDFPage.get_pages(f, pagenos=[pageno], maxpages=0)\n                page = next(page_iter, None)\n                if page is None:\n                    raise InputFileError(\n                        f\"pdfminer could not process page {pageno} (counting from 0).\"\n                    )\n                interp.process_page(page)\n        except PDFTextExtractionNotAllowed as e:\n            raise EncryptedPdfError() from e\n\n    return dev.get_result()\n\n\nclass PdfMinerState:\n    \"\"\"Provide a context manager for using pdfminer.six.\n\n    This ensures that the file is closed. It also provides a cache of pages\n    from the PDF so that they can be reused if needed, to improve performance.\n    \"\"\"\n\n    def __init__(self, infile: Path, pscript5_mode: bool) -> None:\n        \"\"\"Initialize the context manager.","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/ocrmypdf/OCRmyPDF/blob/5074a0b0e109362422b768fd271ed84bf717c4ec/src/ocrmypdf/pdfinfo/layout.py#L295-L331","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Validate the PDF first with a tool like qpdf --check or pikepdf open and repair the input","Ensure pageno is within the page range reported by PdfInfo for the same file","If the PDF is corrupt, run OCRmyPDF with input file repair or preprocess with qpdf --linearize / pikepdf","Check the file isn't being modified concurrently during processing"],"exampleFix":"import pikepdf\ntry:\n    with pikepdf.open(path):\n        pass\nexcept pikepdf.PdfError:\n    repaired = path.with_suffix('.repaired.pdf')\n    pikepdf.open(path).save(repaired)\n    path = repaired\n# now run get_page_analysis(path, pageno)","handlingStrategy":"validation","validationCode":"import pikepdf\ntry:\n    with pikepdf.open(path) as pdf:\n        n = len(pdf.pages)\n    assert 0 <= pageno < n\nexcept pikepdf.PdfError:\n    raise ValueError('input PDF is corrupt; repair before analysis')","typeGuard":null,"tryCatchPattern":"try:\\n    analysis = get_page_analysis(path, pageno)\\nexcept InputFileError as e:\\n    logger.warning('page %d unparseable: %s', pageno, e)\\n    analysis = None","preventionTips":["Validate PDFs with qpdf --check before batch processing","Repair corrupt files with pikepdf before per-page analysis","Cross-check page counts between pikepdf and pdfminer for suspicious files"],"tags":["pdf","pdfminer","corrupt-input","page-parsing"],"backgroundTag":"corrupt-pdf-input","analyzedSha":"5074a0b0e109362422b768fd271ed84bf717c4ec","analyzedAt":"2026-08-27T11:57:38.523Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}