mozilla/pdf.js · warning · FormatError
Encoding is not a Name nor a Dict
Error message
Encoding is not a Name nor a Dict
What it means
Thrown when a font's /Encoding entry is neither a Name (e.g. /WinAnsiEncoding) nor a Dictionary (containing /BaseEncoding and /Differences). Per the PDF spec, /Encoding must be one of those two forms. Unlike most guards here, this one is gated by options.ignoreErrors — if stopAtErrors is false it degrades to a warning and falls back to a default encoding.
Source
Thrown at src/core/evaluator.js:3677
const data = xref.fetchIfRef(entry);
if (typeof data === "number") {
index = data;
} else if (data instanceof Name) {
differences[index++] = data.name;
} else {
throw new FormatError(
`Invalid entry in 'Differences' array: ${data}`
);
}
}
}
} else if (encoding instanceof Name) {
baseEncodingName = encoding.name;
} else {
const msg = "Encoding is not a Name nor a Dict";
if (!this.options.ignoreErrors) {
throw new FormatError(msg);
}
warn(msg);
}
// According to table 114 if the encoding is a named encoding it must be
// one of these predefined encodings.
if (
baseEncodingName !== "MacRomanEncoding" &&
baseEncodingName !== "MacExpertEncoding" &&
baseEncodingName !== "WinAnsiEncoding"
) {
baseEncodingName = null;
}
}
const nonEmbeddedFont = !properties.file || properties.isInternalFont,
isSymbolsFontName = getSymbolsFonts()[properties.name];
// Ignore an incorrectly specified named encoding for non-embedded
// symbol fonts (fixes issue16464.pdf).View on GitHub (pinned to 5903d58d58)
Solutions
- Set stopAtErrors: false (or omit it) so this specific check degrades to a warn() and uses a fallback encoding, allowing the rest of the document to render.
- Repair the PDF with qpdf or Ghostscript to rebuild the Encoding entry.
- If authoring, ensure each font /Encoding is either a predefined Name or a proper encoding Dictionary.
- Filter such PDFs upstream if text fidelity is required, since fallback encodings will mis-map glyphs.
Example fix
// before
getDocument({ url, stopAtErrors: true }); // throws on bad Encoding
// after
getDocument({ url }); // ignoreErrors defaults true -> warn + fallback encoding Defensive patterns
Strategy: validation
Validate before calling
// This guard is already gated by options.ignoreErrors in PDF.js itself.
// To benefit from the degrade-to-warning path, do NOT set stopAtErrors:
const pdf = await getDocument({ url /*, stopAtErrors: false is default */ }).promise;
// The font will load with a fallback encoding; only a console.warn is emitted. Prevention
- Leave stopAtErrors at its default (false) so this specific check warns rather than throws.
- Repair /Encoding entries with Ghostscript or qpdf before processing if text fidelity matters.
- If you must use stopAtErrors: true, catch FormatError per page and skip.
When it happens
Trigger: A font dictionary whose /Encoding is a string, number, array, null, or any non-Name non-Dict object. Fires in PartialEvaluator.translateFont during page/font load. With ignoreErrors=true (the default render path) it logs a warning and continues; with stopAtErrors=true it propagates as an exception.
Common situations: Corrupt or non-conformant PDFs from buggy generators. Also appears after partial PDF repair tools that stripped the encoding object. Frequently seen alongside other font errors in scraped/faxed documents.
Related errors
- Invalid entry in 'Differences' array: ${data}
- FontFile should be a stream
- FontFile is empty
- Max size of CID is 65,535
- invalid font Subtype
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/5f1ab2233ff57c77.
Report an issue: GitHub.