{{ title }}

This sample shows how custom fonts can be embedded into a document. Read More

Along with use of the standard fonts, PdfDocument also provides an ability to embed custom fonts into document. The following font formats are supported: .ttf, .ttc, .dfont.

First of all, a custom font must be registered using the registerFont (or registerFontAsync) method. This method loads font from a URL and associates it with a specified font family name and font attributes (like the style, weight, whether it is a serif or sans serif font etc). After that the font family name can be used in association with PdfFont class just like any other standard font.

For example:

doc.registerFont({
    source: "resources/fonts/fira/FiraSans-Regular.ttf",
    name: "fira",
    style: "normal",
    weight: "normal",
    sansSerif: true
});

doc.drawText("Here is the FiraSans-Regular font.", null, null, {
    // an equivalent of font: new wijmo.pdf.PdfFont("fira", 10, "normal", "normal")
    font: new wijmo.pdf.PdfFont("fira")
});

In this sample, the Fira font family is used and two fonts, FiraSans-Regular.ttf and FiraSans-Bold.ttf, are embedded into the document.