Differences to Other fontkit Versions ​
Other Versions ​
There are a number of other versions of fontkit available:
fontkit, the original fontkit (upstream)@pdf-lib/fontkit, thefontkitversion used bypdf-lib@foliojs-fork, a popular fork of the original fontkit
Notable Differences ​
The most important differences are:
- Fully Typed: Written from the ground up in TypeScript, eliminating the need for external
@types/fontkitdefinitions. - Modernised Module Structure: Full API exposed via clean named exports (
TrueTypeFont,TrueTypeCollection, other individual font classes, etc.), alongside a default export for backwards compatibility. - Static Format Identifiers: Font classes and font collections expose a
static readonly objType(e.g.,WOFF2Font.objType === font.objType) matching instance.objTypeproperties to enable type-safe format checks without string literal guessing. - Strongly Typed Font Tables: Low-level font tables and structures (such as
cmap,hmtx,OS2, ormorx) have been refactored into strict, strongly typed interfaces and (discriminated) unions. - Modern Tooling & Zero Legacy Dependencies: Updated build pipelines, package exports, and test suites targeting modern Node.js runtime environments and ESM/CJS dual-package resolution.
- Ported Bugfixes: All known bugfixes from the other fontkit versions have been ported to
@pdfa-lab/fontkit. - Actively Maintained: This fork will receive regular dependency updates. Bugfixes and other pull requests are welcome!
- Flexible Subset Streaming: You can use the new and simple
encode()or the legacyencodeStream()method for subset serialisation.
Incompatibilities ​
An effort has been made to maintain maximum compatibility with upstream fontkit and other versions. The following known incompatibilities exist:
- All tables in
@pdfa-lab/fontkitare nullable! When you access a table, you always have to check whether it is actually present. The hand-crafted interfaces for otherfontkitversions, suggest that some tables likeCFF,OS/2,head,hhea, orpostare always present, which is by no means guaranteed by the library. But the library contains methods that elegantly validate font features and cast at the same time so that you can safely access certain subsets of tables, see Font Type Narrowing! - The CommonJS module does not have a default export: You have to change
const fontkit = require('@pdfa-lab/fontkit')toconst { fontkit } = require('@pdfa-lab/fontkit'). - The discriminating property
objTypeis preferred over the deprecatedtype.