Skip to content

zeropdf v1.5.0


zeropdf / loadGoogleFont

Function: loadGoogleFont()

ts
function loadGoogleFont(family, options?): Promise<Uint8Array<ArrayBufferLike>>;

Defined in: src/google-fonts.ts:47

Downloads a Google Font and returns its raw TrueType/OpenType bytes, ready to pass to PdfDocument.embedTrueTypeFont or as a face in PdfDocument.registerFontFamily.

The Google Fonts CSS API serves woff2 (Brotli-compressed) to clients that advertise woff2 support — such as browsers — which this zero-dependency engine cannot decode. Clients that do not advertise woff2 support, such as Node, receive an embeddable .ttf/.otf file. Call this from Node; in the browser, fetch a .ttf/.otf yourself and pass it to embedTrueTypeFont.

Parameters

ParameterTypeDescription
familystringGoogle Font family name, e.g. "Inter" or "Roboto Slab".
optionsLoadGoogleFontOptionsWeight, style, subsetting, and network options.

Returns

Promise<Uint8Array<ArrayBufferLike>>

The font file bytes.

Example

ts
const bytes = await loadGoogleFont("Inter", { weight: 700 });
const inter = doc.embedTrueTypeFont(bytes, { family: "Inter" });
doc.addPage().text("Hello", { font: inter, fontSize: 24 });

Released under the ISC license.