Fonts

This sample shows how to draw text using different fonts.


Standard fonts

Out of the box PdfDocument supports the following fonts: Courier, Helvetica, Times, Symbol, ZapfDingbats. The first three fonts have four typefaces each, "normal", "bold", "oblique" and "bold oblique". This gives us a set of fonts known as "14 Standard PDF fonts".


Setting up the font

The PdfFont class describes a particular font and its constructor accepts the following arguments:

  • Font family: A font family name or a prioritized list of font family names separated by a comma, including general font family names like "monospace", "serif" etc. PdfDocument will use the closest registered font. For example, "times", "Roboto, serif". The standard fonts are represented by the following values: "courier", "helvetica", "times", "symbol", "zapfdingbats".
  • Font size.
  • Font style: One of the following values: "normal", "italic", "oblique".
  • Font weight: One of the following values: "normal", "bold", "100", "200", "300", "400", "500", "600", "700", "800", "900".

The following instance is the default document font in terms of PdfDocument:

new wijmo.pdf.PdfFont("times", 10, "normal", "normal")

Using the font

In PdfDocument, the font can be specified in two ways:

  • By passing PdfFont instance directly to drawText as the options.font property.
    doc.drawText("Lorem", null, null, {
        font: new wijmo.pdf.PdfFont("times", 10, "normal", "bold")
    });
  • By changing the default document font using the doc.setFont method first. It will be used if you call drawText method without passing a font to it. This approach is useful when a lot of text with the same font is needed to be drawn.
    doc.setFont(new wijmo.pdf.PdfFont("times", 10, "normal", "bold"));
    doc.drawText("Lorem");

If font with exact given style and weight properties is not found, then the closest registered font will be used.


This sample shows how to use drawText and doc.setFont methods to draw text using different fonts.