{"record":{"id":"6b7d1ed032c9209c","repo":"mozilla/pdf.js","slug":"page-count-is-not-an-integer","errorCode":null,"errorMessage":"Page count is not an integer.","messagePattern":"Page count is not an integer\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"warning","filePath":"src/core/document.js","lineNumber":1772,"sourceCode":"    let numPages;\n\n    try {\n      await Promise.all([\n        pdfManager.ensureDoc(\"xfaFactory\"),\n        pdfManager.ensureDoc(\"linearization\"),\n        pdfManager.ensureCatalog(\"numPages\"),\n      ]);\n\n      if (this.xfaFactory) {\n        return; // The Page count is always calculated for XFA-documents.\n      } else if (this.linearization) {\n        numPages = this.linearization.numPages;\n      } else {\n        numPages = catalog.numPages;\n      }\n\n      if (!Number.isInteger(numPages)) {\n        throw new FormatError(\"Page count is not an integer.\");\n      } else if (numPages <= 1) {\n        return;\n      }\n      await this.getPage(numPages - 1);\n    } catch (reason) {\n      // Clear out the various caches to ensure that we haven't stored any\n      // inconsistent and/or incorrect state, since that could easily break\n      // subsequent `this.getPage` calls.\n      this.#pagePromises.delete(numPages - 1);\n      await this.cleanup();\n\n      if (reason instanceof XRefEntryException && !recoveryMode) {\n        throw new XRefParseException();\n      }\n      warn(`checkLastPage - invalid /Pages tree /Count: ${numPages}.`);\n\n      let pagesTree;\n      try {","sourceCodeStart":1754,"sourceCodeEnd":1790,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/document.js#L1754-L1790","documentation":"FormatError thrown inside checkHeader / numPages validation when the resolved numPages (from linearization.numPages or catalog.numPages) is not an integer. The surrounding try/catch clears caches and triggers recovery, so end-user impact is usually degraded performance rather than a hard failure. It indicates the page count entry in the linearization dict or catalog Pages /Count is corrupt.","triggerScenarios":"A linearization dict whose /N is fractional or missing; a catalog whose /Pages /Count is non-numeric; a corrupt PDF where the Pages tree root has no integer Count.","commonSituations":"Truncated or hand-edited PDFs; buggy producers that omit /Count; partial downloads.","solutions":["Repair with qpdf --check / --fix or Acrobat Save As.","Re-generate the PDF with a conformant producer.","If you observe degraded page-count detection, accept the recovery and log for follow-up."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":["Repair the PDF (qpdf --check / Acrobat Save As) when this warning recurs.","Treat recurrence as a producer bug—log the file origin for follow-up.","Do not over-react; the surrounding recovery clears caches and re-derives the page count."],"tags":["linearization","format-error","recovery","page-count","catalog"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}