mozilla/pdf.js · error · FormatError
Page dictionary kid reference points to wrong type of object
Error message
Page dictionary kid reference points to wrong type of object.
What it means
Thrown in Catalog.getPageDict() (catalog.js:1379) when a node popped off nodesToVisit is neither a Ref nor a Dict. Kids entries should be Refs (resolving to Dicts); after a Ref resolves to a non-Dict it is pushed back and re-examined here. If that object is still not a Dict, the kid reference is the wrong type.
Source
Thrown at src/core/catalog.js:1379
// Help improve performance of the `getPageIndex` method.
if (!pageIndexCache.has(currentNode)) {
pageIndexCache.put(currentNode, currentPageIndex);
}
if (currentPageIndex === pageIndex) {
return [obj, currentNode];
}
currentPageIndex++;
continue;
}
}
nodesToVisit.push(obj);
continue;
}
// Must be a child page dictionary.
if (!(currentNode instanceof Dict)) {
throw new FormatError(
"Page dictionary kid reference points to wrong type of object."
);
}
const { objId } = currentNode;
let count = currentNode.getRaw("Count");
if (count instanceof Ref) {
count = await xref.fetchAsync(count);
}
if (Number.isInteger(count) && count >= 0) {
// Cache the Kids count, since it can reduce redundant lookups in
// documents where all nodes are found at *one* level of the tree.
if (objId && !pageKidsCountCache.has(objId)) {
pageKidsCountCache.put(objId, count);
}
// Skip nodes where the page can't be.
if (currentPageIndex + count <= pageIndex) {View on GitHub (pinned to 5903d58d58)
Solutions
- Repair the PDF with qpdf/mutool to rebuild /Kids as proper indirect references to dictionaries.
- Validate the page tree with 'qpdf --check' before relying on getPage().
- Load with error recovery enabled and accept that the affected page may be unreachable.
- If producing PDFs, ensure every /Kids entry is an indirect reference to a /Page or /Pages dictionary.
Defensive patterns
Strategy: try-catch
Validate before calling
// Pre-validation requires walking the page tree, which is the failing operation. // Repair the PDF instead: mutool clean in.pdf out.pdf
Try / catch
try {
const page = await pdf.getPage(n);
} catch (err) {
if (/kid reference points to wrong type/i.test(err?.message)) {
console.warn('Malformed /Kids entry; repair the PDF', err);
} else throw err;
} Prevention
- Ensure every /Kids entry is an indirect reference to a dictionary when producing PDFs.
- Repair malformed page trees with qpdf/mutool.
- Run 'qpdf --check' on inputs.
- Enable recovery/ignoreErrors for resilient loading.
When it happens
Trigger: A Kids array entry is a non-Ref primitive (number/string/null) and is not a Dict, OR a Ref resolves to a non-dictionary object (stream, array, scalar). Reached during pdfDocument.getPage(n) traversal.
Common situations: Corrupt PDF with a malformed /Kids array containing scalar/null entries; a Ref pointing at the wrong (non-dict) object due to a shifted xref; a hand-edited page tree.
Related errors
- Node must be a dictionary.
- Pages tree contains circular reference.
- Page dictionary kids object is not an array.
- Page index ${pageIndex} not found.
- The reference does not point to a /Page dictionary.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/e28a29fc65f157b8.
Report an issue: GitHub.