mozilla/pdf.js · critical · FormatError

Page count in top-level pages dictionary is not an integer.

Error message

Page count in top-level pages dictionary is not an integer.

What it means

Thrown by the _pagesCount getter (catalog.js:753) when the /Pages root dictionary's /Count value is not an integer. /Count must be an integer giving the total number of pages; a float, string, null, or name makes the page count unknowable.

Source

Thrown at src/core/catalog.js:753

      on: parseOnOff(config.get("ON")),
      off: parseOnOff(config.get("OFF")),
      order: parseOrder(config.get("Order")),
      groups: [...groupRefCache],
    };
  }

  setActualNumPages(num = null) {
    this.#actualNumPages = num;
  }

  get hasActualNumPages() {
    return this.#actualNumPages !== null;
  }

  get _pagesCount() {
    const obj = this.toplevelPagesDict.get("Count");
    if (!Number.isInteger(obj)) {
      throw new FormatError(
        "Page count in top-level pages dictionary is not an integer."
      );
    }
    return shadow(this, "_pagesCount", obj);
  }

  get numPages() {
    return this.#actualNumPages ?? this._pagesCount;
  }

  get destinations() {
    const dests = new Map();

    for (const obj of this.#readDests()) {
      if (obj instanceof NameTree) {
        for (const [key, value] of obj.getAll()) {
          const dest = fetchDest(value);
          if (dest) {

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Repair with 'qpdf --linearize' or 'mutool clean' to normalise /Count to an integer.
  2. If you control the producer, ensure /Count is emitted as a PDF integer token.
  3. Validate the PDF with 'qpdf --check' to surface the malformed /Count before loading.
  4. Fall back to loading with a repaired copy when the original is rejected.
Defensive patterns

Strategy: try-catch

Validate before calling

// Cannot read /Count cheaply pre-load; rely on repair for known-bad producers.
// If you generate PDFs, write /Count as an integer.
// For inputs, run: qpdf --check in.pdf  (reports malformed /Count)

Try / catch

try {
  const pdf = await getDocument({ data: arrayBuffer }).promise;
  const n = pdf.numPages; // access triggers _pagesCount
} catch (err) {
  if (/Page count.*not an integer/i.test(err?.message)) {
    throw new Error('PDF /Count is malformed; repair with qpdf/mutool.', { cause: err });
  }
  throw err;
}

Prevention

When it happens

Trigger: this.toplevelPagesDict.get('Count') returns a non-integer (e.g., 3.0 stored as a real, a string, or undefined/null). Reached via the numPages getter (numPages falls back to _pagesCount when no actualNumPages is set), which is used pervasively during rendering and indexing.

Common situations: A PDF producer that wrote /Count as a floating-point or wrong type; a corrupt object where /Count was overwritten; a page tree root missing /Count; an edited PDF with a malformed count.

Related errors


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