{"record":{"id":"02e263682efb273b","repo":"mozilla/pdf.js","slug":"invalid-type-in-pagelabel-dictionary","errorCode":null,"errorMessage":"Invalid type in PageLabel dictionary.","messagePattern":"Invalid type in PageLabel dictionary\\.","errorType":"exception","errorClass":"FormatError","httpStatus":null,"severity":"warning","filePath":"src/core/catalog.js","lineNumber":876,"sourceCode":"    let style = null,\n      prefix = \"\";\n\n    let currentLabel = \"\",\n      currentIndex = 1;\n\n    for (let i = 0, ii = this.numPages; i < ii; i++) {\n      const labelDict = nums.get(i);\n\n      if (labelDict !== undefined) {\n        if (!(labelDict instanceof Dict)) {\n          throw new FormatError(\"PageLabel is not a dictionary.\");\n        }\n\n        if (\n          labelDict.has(\"Type\") &&\n          !isName(labelDict.get(\"Type\"), \"PageLabel\")\n        ) {\n          throw new FormatError(\"Invalid type in PageLabel dictionary.\");\n        }\n\n        if (labelDict.has(\"S\")) {\n          const s = labelDict.get(\"S\");\n          if (!(s instanceof Name)) {\n            throw new FormatError(\"Invalid style in PageLabel dictionary.\");\n          }\n          style = s.name;\n        } else {\n          style = null;\n        }\n\n        if (labelDict.has(\"P\")) {\n          const p = labelDict.get(\"P\");\n          if (typeof p !== \"string\") {\n            throw new FormatError(\"Invalid prefix in PageLabel dictionary.\");\n          }\n          prefix = stringToPDFString(p);","sourceCodeStart":858,"sourceCodeEnd":894,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/catalog.js#L858-L894","documentation":"Thrown in Catalog.#readPageLabels() (catalog.js:876) when a PageLabel dictionary has a /Type entry that is not the Name /PageLabel. /Type is optional, but if present it must be /PageLabel. Like the other PageLabel errors, the pageLabels getter catches this and warns 'Unable to read page labels.', returning null.","triggerScenarios":"A PageLabel dict where /Type is present but isName(get('Type'), 'PageLabel') is false (a different name, a string, or another type). Reached while iterating labels for pdfDocument.pageLabels.","commonSituations":"A producer that wrote a wrong /Type (e.g., /Page instead of /PageLabel); an edited/corrupt label dictionary. Non-fatal; labels are dropped.","solutions":["Accept the degraded behaviour (pageLabels returns null with a console warning) if labels are cosmetic.","Repair the PDF with qpdf/mutool to strip or fix the bad /Type.","When producing PDFs, either omit /Type on PageLabel dicts or set it to /PageLabel exactly.","Handle null pageLabels gracefully in your UI."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Already degraded to a warning by PDF.js; consume pageLabels defensively:\nconst labels = pdf.pageLabels; // null when the label tree is invalid\nrenderPageLabels(labels ?? Array.from({ length: pdf.numPages }, (_, i) => String(i + 1)));","preventionTips":["Handle null pageLabels gracefully in the UI.","Repair the PDF to fix /Type on PageLabel dicts if labels matter.","Omit /Type or set it to /PageLabel exactly when producing PDFs.","Do not block document viewing on label availability."],"tags":["pdf-structure","catalog","page-labels","corrupt-pdf","validation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}