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

  1. Accept the degraded null labels if prefixes are cosmetic.
  2. Repair with qpdf/mutool to remove or fix the /P entry.
  3. When producing PDFs, write /P as a PDF text string.
  4. 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

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


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