Skip to content

a11ydocs v1.7.0


a11ydocs / 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 — and an embeddable .ttf/.otf to other clients, such as Node. Both work: when a woff2 URL is served, the @barrierbreak/a11ydocs-pdf/woff2 decoder is loaded on demand and the file is converted to TTF bytes before returning.

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.