mozilla/pdf.js · warning · FormatError

Invalid type in PageLabel dictionary.

Error message

Invalid type in PageLabel dictionary.

What it means

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.

Source

Thrown at src/core/catalog.js:876

    let style = null,
      prefix = "";

    let currentLabel = "",
      currentIndex = 1;

    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);

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Accept the degraded behaviour (pageLabels returns null with a console warning) if labels are cosmetic.
  2. Repair the PDF with qpdf/mutool to strip or fix the bad /Type.
  3. When producing PDFs, either omit /Type on PageLabel dicts or set it to /PageLabel exactly.
  4. Handle null pageLabels gracefully in your UI.
Defensive patterns

Strategy: fallback

Try / catch

// Already degraded to a warning by PDF.js; consume pageLabels defensively:
const labels = pdf.pageLabels; // null when the label tree is invalid
renderPageLabels(labels ?? Array.from({ length: pdf.numPages }, (_, i) => String(i + 1)));

Prevention

When it happens

Trigger: 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.

Common situations: A producer that wrote a wrong /Type (e.g., /Page instead of /PageLabel); an edited/corrupt label dictionary. Non-fatal; labels are dropped.

Related errors


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