mozilla/pdf.js · error · FormatError
Dictionary key must be a name object
Error message
Dictionary key must be a name object
What it means
Thrown as a FormatError by Parser.makeInlineImage() while reading the key-value pairs of an inline image dictionary (the tokens between BI and ID). Inline image keys must be Name objects; if a non-Name token appears where a key is expected, the structure is malformed. Unlike the regular dict parser (which just warns and skips), the inline-image path is stricter and throws.
Source
Thrown at src/core/parser.js:545
} else if (state === 2) {
break;
}
}
}
/**
* @param {CipherTransform | null} cipherTransform
* @returns {Streams}
*/
makeInlineImage(cipherTransform) {
const lexer = this.lexer;
const stream = lexer.stream;
const dict = new Dict(this.xref);
let dictLength;
while (!isCmd(this.buf1, "ID") && this.buf1 !== EOF) {
if (!(this.buf1 instanceof Name)) {
throw new FormatError("Dictionary key must be a name object");
}
const key = this.buf1.name;
this.shift();
if (this.buf1 === EOF) {
break;
}
dict.set(key, this.getObj(cipherTransform));
}
if (lexer.beginInlineImagePos !== -1) {
dictLength = stream.pos - lexer.beginInlineImagePos;
}
// Extract the name of the first (i.e. the current) image filter.
const filter = dict.get("F", "Filter");
let filterName;
if (filter instanceof Name) {
filterName = filter.name;
} else if (Array.isArray(filter)) {View on GitHub (pinned to 5903d58d58)
Solutions
- Extract and inspect the page content stream around the BI operator to find the malformed key.
- Re-export or rebuild the PDF with a reliable producer (Ghostscript, qpdf) to normalize the content stream.
- If the image is non-essential, catch FormatError during page rendering to still show the rest of the page.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await page.render({ canvasContext }).promise;
} catch (e) {
if (e.name === 'FormatError' && /name object/.test(e.message)) { /* malformed inline image */ }
else throw e;
} Prevention
- Inspect the page content stream around BI/ID operators for malformed inline images.
- Re-export suspect PDFs with Ghostscript/qpdf to normalize content streams.
- Catch FormatError during render to still display the rest of the page.
When it happens
Trigger: makeInlineImage() loops while buf1 isn't 'ID' or EOF; each buf1 must be a Name. If a number, string, or Cmd appears as a key, the `instanceof Name` check fails and the FormatError fires. Happens in PDF content streams with malformed inline image syntax.
Common situations: A PDF page content stream with a broken BI/ID inline image — e.g. missing a value so the next token (a value) is read as a key, or an encoder that emitted non-name tokens. Often caused by content-stream corruption or a buggy PDF producer. Less common than the regular-dict variant because inline images are rare.
Related errors
- End of file inside array.
- End of file inside dictionary.
- Duplicate entry in "${this._type}" tree.
- Parent must be a dictionary.
- Kids must be an array.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/fc881c9a2f7922d3.
Report an issue: GitHub.