mozilla/pdf.js · error · FormatError
invalid font name
Error message
invalid font name
What it means
Thrown by translateFont() after all font-name resolution attempts (descriptor /FontName, BaseFont-derived name, known-font-name heuristics) fail to produce a Name object for the font. Every code path that assigns fontName has run and none yielded a valid Name, so the font cannot be loaded because glyph metrics and file lookup depend on a name. This is the final, unrecoverable guard before font-file fetching.
Source
Thrown at src/core/evaluator.js:4605
);
// - Workaround for cases where e.g. fontNameStr = 'Arial' and
// baseFontStr = 'Arial,Bold' (needed when no font file is embedded).
//
// - Workaround for cases where e.g. fontNameStr = 'wg09np' and
// baseFontStr = 'Wingdings-Regular' (fixes issue7454.pdf).
if (
fontNameStr &&
baseFontStr &&
(baseFontStr.startsWith(fontNameStr) ||
(!isKnownFontName(fontNameStr) && isKnownFontName(baseFontStr)))
) {
fontName = null;
}
fontName ||= baseFont;
}
if (!(fontName instanceof Name)) {
throw new FormatError("invalid font name");
}
let fontFile, fontFileN, subtype, length1, length2, length3;
try {
for (const n of ["FontFile", "FontFile2", "FontFile3"]) {
fontFile = descriptor.get(n);
if (fontFile) {
fontFileN = n;
break;
}
}
if (fontFile) {
if (!(fontFile instanceof BaseStream)) {
throw new FormatError("FontFile should be a stream");
} else {
if (fontFile.isAsync) {
const bytes = await fontFile.asyncGetBytes();View on GitHub (pinned to 5903d58d58)
Solutions
- Repair the PDF with Ghostscript (gs -sDEVICE=pdfwrite -dPDFSETTINGS=/default) to rebuild font metadata.
- If authoring, ensure at least one of /FontDescriptor >> /FontName or /BaseFont is a valid Name.
- Isolate the page with stopAtErrors: true; the rest of the document will render with fallback fonts.
- If you control the consumer app, surface a user-visible warning that a font could not be identified and text may be substituted.
Defensive patterns
Strategy: try-catch
Try / catch
try {
await page.render({ canvasContext, viewport });
} catch (e) {
if (e.name === 'FormatError' && /invalid font name/.test(e.message)) {
// no resolvable font name — PDF.js cannot load this font
} else throw e;
} Prevention
- Ensure at least one of /FontDescriptor >> /FontName or /BaseFont is a valid Name on every font.
- Repair heavily stripped PDFs with Ghostscript to rebuild font metadata.
- Use per-page try/catch so one unidentifiable font does not abort the whole document.
When it happens
Trigger: A font dictionary whose /FontDescriptor lacks /FontName, whose /BaseFont is not a Name, and where none of the heuristics (startsWith, isKnownFontName) recovered a usable name. Fires at the end of the name-resolution block in translateFont().
Common situations: Severely malformed font dictionaries, often from corrupt or hand-built PDFs. Also occurs when a font subsetting tool stripped identifying names but left the structure otherwise intact. Rarely encountered with mainstream PDF producers.
Related errors
- Invalid entry in 'Differences' array: ${data}
- Encoding is not a Name nor a Dict
- Max size of CID is 65,535
- invalid font Subtype
- Descendant fonts are not specified
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/5de619a7dfd47337.
Report an issue: GitHub.