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

  1. Rely on the built-in degradation (pageLabels becomes null) if labels are non-critical.
  2. Repair the PDF (qpdf/mutool) to convert /S to a proper name.
  3. When producing PDFs, write /S as a name object: /D, /R, /r, /A, or /a.
  4. 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

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


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/9d1556d4731a6366. Report an issue: GitHub.