mozilla/pdf.js · warning · FormatError
Invalid prefix in PageLabel dictionary.
Error message
Invalid prefix in PageLabel dictionary.
What it means
Thrown in Catalog.#readPageLabels() (catalog.js:892) when a PageLabel dictionary has a /P (prefix) entry that is not a string. /P, when present, must be a text string used as the label prefix. Caught and downgraded to a warning by the pageLabels getter.
Source
Thrown at src/core/catalog.js:892
!isName(labelDict.get("Type"), "PageLabel")
) {
throw new FormatError("Invalid type in PageLabel dictionary.");
}
if (labelDict.has("S")) {
const s = labelDict.get("S");
if (!(s instanceof Name)) {
throw new FormatError("Invalid style in PageLabel dictionary.");
}
style = s.name;
} else {
style = null;
}
if (labelDict.has("P")) {
const p = labelDict.get("P");
if (typeof p !== "string") {
throw new FormatError("Invalid prefix in PageLabel dictionary.");
}
prefix = stringToPDFString(p);
} else {
prefix = "";
}
if (labelDict.has("St")) {
const st = labelDict.get("St");
if (!(Number.isInteger(st) && st >= 1)) {
throw new FormatError("Invalid start in PageLabel dictionary.");
}
currentIndex = st;
} else {
currentIndex = 1;
}
}
switch (style) {View on GitHub (pinned to 5903d58d58)
Solutions
- Accept the degraded null labels if prefixes are cosmetic.
- Repair with qpdf/mutool to remove or fix the /P entry.
- When producing PDFs, write /P as a PDF text string.
- Treat null pageLabels as 'unavailable' in your application.
Defensive patterns
Strategy: fallback
Try / catch
const labels = pdf.pageLabels; // null if /P is invalid
if (!labels) { /* use default numbering */ } Prevention
- Handle null labels gracefully.
- Repair the PDF to fix /P if prefixes are needed.
- Write /P as a PDF text string when producing PDFs.
- Do not require prefixes for core functionality.
When it happens
Trigger: labelDict.get('P') exists but typeof p !== 'string' (e.g., a name, number, or array). Reached while computing pdfDocument.pageLabels.
Common situations: A producer that wrote /P as the wrong object type; a corrupt prefix entry. Non-fatal; labels are dropped.
Related errors
- Invalid type in PageLabel dictionary.
- Invalid style in PageLabel dictionary.
- Invalid start in PageLabel dictionary.
- Invalid style "${style}" in PageLabel dictionary.
- Page count in top-level pages dictionary is not an integer.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/4ff36422786ecb50.
Report an issue: GitHub.