mozilla/pdf.js · warning · FormatError
Invalid style in PageLabel dictionary.
Error message
Invalid style in PageLabel dictionary.
What it means
Thrown in Catalog.#readPageLabels() (catalog.js:882) when a PageLabel dictionary has an /S (style) entry that is not a Name. /S, when present, must be one of the Names /D, /R, /r, /A, /a. A non-Name /S is invalid. Caught and downgraded to a warning by the pageLabels getter.
Source
Thrown at src/core/catalog.js:882
for (let i = 0, ii = this.numPages; i < ii; i++) {
const labelDict = nums.get(i);
if (labelDict !== undefined) {
if (!(labelDict instanceof Dict)) {
throw new FormatError("PageLabel is not a dictionary.");
}
if (
labelDict.has("Type") &&
!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");View on GitHub (pinned to 5903d58d58)
Solutions
- Rely on the built-in degradation (pageLabels becomes null) if labels are non-critical.
- Repair the PDF (qpdf/mutool) to convert /S to a proper name.
- When producing PDFs, write /S as a name object: /D, /R, /r, /A, or /a.
- Surface 'labels unavailable' in the UI rather than failing the document.
Defensive patterns
Strategy: fallback
Try / catch
const labels = pdf.pageLabels; // null if /S is invalid
if (!labels) {
// degrade to default numeric labels
} Prevention
- Accept null labels as the degraded state for invalid /S.
- Repair the PDF (qpdf/mutool) when styles are required.
- Write /S as a name (/D,/R,/r,/A,/a) when producing PDFs.
- Keep label display optional in your UX.
When it happens
Trigger: labelDict.get('S') exists but is not a Name instance (e.g., the string 'D' instead of the Name /D). Reached while computing pdfDocument.pageLabels.
Common situations: A producer that serialized the style as a literal string instead of a name object; a corrupt/edited label dict. Non-fatal.
Related errors
- Invalid type in PageLabel dictionary.
- Invalid prefix 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/9d1556d4731a6366.
Report an issue: GitHub.