parallax/jsPDF · error · Error
No unicode cmap for font
Error message
No unicode cmap for font
What it means
Thrown in TTFFont.registerTTF after parsing when the font's cmap table has no Unicode subtable (this.cmap.unicode is falsy). jsPDF's text layout relies on a Unicode cmap to map characters to glyph IDs; without one it cannot render arbitrary text, so it aborts. Symbol/fonts with only platform-specific or Mac Roman encodings trigger this.
Source
Thrown at src/libs/ttffont.js:128
_ref === 5 ||
_ref === 7;
this.isScript = this.familyClass === 10;
this.flags = 0;
if (this.post.isFixedPitch) {
this.flags |= 1 << 0;
}
if (this.isSerif) {
this.flags |= 1 << 1;
}
if (this.isScript) {
this.flags |= 1 << 3;
}
if (this.italicAngle !== 0) {
this.flags |= 1 << 6;
}
this.flags |= 1 << 5;
if (!this.cmap.unicode) {
throw new Error("No unicode cmap for font");
}
};
TTFFont.prototype.characterToGlyph = function(character) {
var _ref;
return (
((_ref = this.cmap.unicode) != null ? _ref.codeMap[character] : void 0) ||
0
);
};
TTFFont.prototype.widthOfGlyph = function(glyph) {
var scale;
scale = 1000.0 / this.head.unitsPerEm;
return this.hmtx.forGlyph(glyph).advance * scale;
};
TTFFont.prototype.widthOfString = function(string, size, charSpace) {
var charCode, i, scale, width, _ref;
string = "" + string;
width = 0;View on GitHub (pinned to a3930ce03a)
Solutions
- Use a font that includes a Unicode cmap (most modern .ttf do; verify with fonttools `ttdump`/`ttx`).
- Re-subset the font ensuring the 'cmap' table's format 4 / format 12 Unicode subtable is retained.
- If you only need glyphs, switch to a standard jsPDF font that already has Unicode support.
Example fix
// before (symbol font with no unicode cmap)
doc.addFileToVFS('MySymbols.ttf', bytes);
doc.addFont('MySymbols.ttf', 'MySymbols', 'normal'); // throws on registerTTF
// after (re-export font with a unicode cmap subtable, then register)
doc.addFileToVFS('MySymbols-uni.ttf', bytesWithUnicodeCmap);
doc.addFont('MySymbols-uni.ttf', 'MySymbols', 'normal'); Defensive patterns
Strategy: try-catch
Validate before calling
// Lightweight pre-check: parse the cmap table to confirm a unicode subtable. // In practice, wrap registration in try/catch (see tryCatchPattern). null;
Type guard
// Requires parsing; no cheap guard. Use try/catch around TTFFont.open / addFont.
Try / catch
try {
doc.addFont(fontKey, family, style);
} catch (e) {
if (/No unicode cmap for font/.test(e.message)) {
console.warn('Font lacks a unicode cmap; use a font with format 4/12 cmap');
return;
}
throw e;
} Prevention
- Use fonts known to ship a Unicode cmap (format 4 or 12).
- When subsetting, retain the Unicode cmap subtable.
- Avoid pure symbol/Mac-encoded fonts for general text.
When it happens
Trigger: Registering a TTF that lacks a Unicode (platform 3 encoding 1, or platform 0) cmap subtable -- e.g. pure symbol fonts, some old Mac-only fonts, or a subset that dropped the Unicode cmap.
Common situations: Using a dingbat/symbol font; subsetting a font with a tool that omitted the Unicode cmap; embedding a font converted from an obscure source.
Related errors
- Invalid PDF Name Object: " + str + ", Only accept ASCII char
- TTCF not supported.
- Invalid Combination of fontweight and fontstyle
- Invalid arguments passed to PubSub.subscribe (jsPDF-module)
- Invalid argument passed to jsPDF.setCreationDate
AI-assisted analysis of parallax/jsPDF@a3930ce03a (2026-08-13).
Data as JSON: /api/errors/34a2a6472ed1ca46.
Report an issue: GitHub.