A library for working with fonts in PDF documents, providing utilities for font loading, embedding, and text rendering.
npm install @peculiar/pdf-font
import { FontFactory, DefaultFonts } from "@peculiar/pdf-font";
// Use default font
const helvetica = FontFactory.createDefault(DefaultFonts.Helvetica);
// Load custom TrueType font
const fontBuffer = await loadFontFile("path/to/font.ttf");
const customFont = FontFactory.create(fontBuffer);
// Get font metrics
const metrics = font.fontInfo;
console.log(metrics.ascent); // Font ascender
console.log(metrics.descent); // Font descender
console.log(metrics.unitsPerEm); // Font units per em
// Get glyph information
const glyph = font.findGlyph(unicodeCodePoint);
console.log(glyph.advanceWidth); // Glyph width
console.log(glyph.unicode); // Unicode values
// Access font name information
const fontName = font.fontInfo.name;
console.log(fontName.fontFamily); // Font family name
console.log(fontName.fullName); // Full font name
console.log(fontName.postScriptName); // PostScript name
This project is dual-licensed under the AGPL-3.0 and a Commercial License:
The library is open-source and freely available under the terms of the Affero General Public License (AGPL-3.0). This ensures that modifications and usage in network-based applications (e.g., SaaS) must be shared under the same license.
You can use the library under AGPL-3.0 if:
- Your project is open-source and distributed under a compatible license
- Your use complies with the AGPL-3.0 requirements
For use in proprietary, closed-source, or commercial projects where the AGPL is not suitable, a commercial license is available. This allows you to use the library without the AGPL's obligations.