{"record":{"id":"20c93ed44248d8d3","repo":"ocrmypdf/OCRmyPDF","slug":"pdfminer-did-not-find-page-pageno-in-the-input-f","errorCode":null,"errorMessage":"pdfminer did not find page {pageno} in the input file.","messagePattern":"pdfminer did not find page (.+?) in the input file\\.","errorType":"exception","errorClass":"InputFileError","httpStatus":null,"severity":"error","filePath":"src/ocrmypdf/pdfinfo/layout.py","lineNumber":364,"sourceCode":"        \"\"\"Enter the context manager.\"\"\"\n        self.file = Path(self.infile).open('rb')\n        self.page_iter = PDFPage.get_pages(self.file)\n        return self\n\n    def __exit__(self, exc_type, exc_value, traceback):\n        \"\"\"Exit the context manager.\"\"\"\n        if self.file:\n            self.file.close()\n        return True\n\n    def get_page_analysis(self, pageno: int):\n        \"\"\"Get the page analysis for a given page.\"\"\"\n        assert self.page_iter is not None, \"must be used as a context manager\"\n        while len(self.page_cache) <= pageno:\n            try:\n                self.page_cache.append(next(self.page_iter))\n            except StopIteration:\n                raise InputFileError(\n                    f\"pdfminer did not find page {pageno} in the input file.\"\n                ) from None\n        page = self.page_cache[pageno]\n        if not page:\n            raise InputFileError(\n                f\"pdfminer could not process page {pageno} (counting from 0).\"\n            )\n        dev = TextPositionTracker(\n            self.rman,\n            laparams=LAParams(\n                all_texts=True, detect_vertical=True, boxes_flow=self.disable_boxes_flow\n            ),\n        )\n        interp = pdfminer.pdfinterp.PDFPageInterpreter(self.rman, dev)\n\n        with patch_pdfminer(self.pscript5_mode):\n            interp.process_page(page)\n","sourceCodeStart":346,"sourceCodeEnd":382,"githubUrl":"https://github.com/ocrmypdf/OCRmyPDF/blob/5074a0b0e109362422b768fd271ed84bf717c4ec/src/ocrmypdf/pdfinfo/layout.py#L346-L382","documentation":"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.","triggerScenarios":"Calling get_page_analysis(pageno) on a PageAnalysisCache with a pageno >= the number of pages pdfminer actually yields (StopIteration while filling page_cache).","commonSituations":"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.","solutions":["Check pageno against the PdfInfo page count for the same file before calling","If counts differ between pikepdf and pdfminer, repair the PDF (qpdf --check / pikepdf)","Verify your loop uses the same zero-based indexing assumption as the library","Reopen a fresh analysis context if the underlying file changed"],"exampleFix":"// before\nfor i in range(info.page_count_pdf)\n    analysis = cache.get_page_analysis(i)  # may raise if pdfminer yields fewer\n// after\ninfo = PdfInfo.from_path(path)\nn = min(info.page_count_pdf, info.page_count_pdfminer)\nfor i in range(n):\n    analysis = cache.get_page_analysis(i)","handlingStrategy":"validation","validationCode":"info = PdfInfo.from_path(path)\nif pageno >= info.page_count_pdf:\n    raise IndexError(f'pageno {pageno} out of range (0..{info.page_count_pdf-1})')","typeGuard":null,"tryCatchPattern":"try:\\n    analysis = cache.get_page_analysis(pageno)\\nexcept InputFileError:\\n    analysis = None  # skip missing page","preventionTips":["Always derive loop bounds from the same PdfInfo object used for analysis","Use consistent zero-based page indexing throughout your pipeline","Handle InputFileError per-page in batch jobs so one bad page doesn't kill the run"],"tags":["pdf","pdfminer","page-range","corrupt-input"],"backgroundTag":"page-index-out-of-range","analyzedSha":"5074a0b0e109362422b768fd271ed84bf717c4ec","analyzedAt":"2026-08-27T11:57:38.523Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}