PdfFont Class
A font that PdfContentBuilder shows text with. A font does not belong to a document: each document that uses it gets its own font objects.
public abstract class PdfFontRemarks
The metrics are in glyph space units, 1/1000 of the font size. The class cannot be derived outside the library and its instances are immutable and thread-safe.
Properties
| Name | Description |
|---|---|
| Ascent | Gets the height above the baseline of the tallest glyphs, in glyph space units (1/1000 em). |
| CapHeight | Gets the height of the flat capital letters, in glyph space units. |
| Descent | Gets the depth below the baseline of the lowest glyphs, a negative number in glyph space units. |
| PostScriptName | Gets the PostScript name of the font, the /BaseFont of its font dictionary. |
Ascent
CapHeight
Descent
PostScriptName
Methods
| Name | Description |
|---|---|
| CanEncode(string) | Indicates whether every character of a text has a glyph in the font. |
| FromFace(FontFace) | Creates a font to embed in the documents that use it from a font face. See PdfFont.Load. |
| GetStandardFont(PdfStandardFont) | Gets a standard font (ISO 32000-2, 9.6.2.2). |
| GetTextWidth(string, double) | Gets the width of a text shown with the font, in user space units, without character or word spacing. |
| Load(ReadOnlySpan<byte>, int) | Loads a TrueType or OpenType font (.ttf, .otf, .ttc, .woff, .woff2) to embed in the documents that use it. |
| Load(string, int) | Loads a TrueType or OpenType font file to embed in the documents that use it. See PdfFont.Load. |
CanEncode(string)
FromFace(FontFace)
PdfFont.csCreates a font to embed in the documents that use it from a font face. See PdfFont.Load.
Parameters
faceFontFace- The face.
Returns
PdfFont The font.
Exceptions
UnsupportedPdfFeatureException- The outlines of the font cannot be embedded, or its license does not allow embedding.
GetStandardFont(PdfStandardFont)
PdfFont.csGets a standard font (ISO 32000-2, 9.6.2.2).
public static PdfFont GetStandardFont(PdfStandardFont font)GetTextWidth(string, double)
PdfFont.csGets the width of a text shown with the font, in user space units, without character or word spacing.
Parameters
Returns
double The width.
Exceptions
ArgumentException- A character of the text has no glyph in the font.
Load overloads
Load(ReadOnlySpan<byte>, int)
PdfFont.csLoads a TrueType or OpenType font (.ttf, .otf, .ttc, .woff, .woff2) to embed in the documents that use it.
public static PdfFont Load(ReadOnlySpan<byte> data, int faceIndex = 0)Parameters
dataReadOnlySpan<byte>- The bytes of the font file.
faceIndexint- The index of the font in a collection (
.ttc); 0 for a file of one font.
Returns
PdfFont The font.
Exceptions
InvalidFontException- The file is not a valid font.
ArgumentOutOfRangeExceptionfaceIndexis not the index of a font of the file.UnsupportedPdfFeatureException- The outlines of the font cannot be embedded (CFF2 or bitmap fonts), or its license does not allow embedding.
Remarks
Each document embeds the subset of the glyphs it shows, in a composite font whose codes are the glyph identifiers (ISO 32000-2, 9.7), with a ToUnicode CMap so that the text can be extracted. The text is shaped with the OpenType layout tables of the font (ligatures, kerning, marks, complex scripts) and ordered by the Unicode Bidirectional Algorithm.
Load(string, int)
PdfFont.csLoads a TrueType or OpenType font file to embed in the documents that use it. See PdfFont.Load.
Parameters
pathstring- The path of the font file.
faceIndexint- The index of the font in a collection (
.ttc); 0 for a file of one font.
Returns
PdfFont The font.
Exceptions
InvalidFontException- The file is not a valid font.
ArgumentOutOfRangeExceptionfaceIndexis not the index of a font of the file.UnsupportedPdfFeatureException- The outlines of the font cannot be embedded, or its license does not allow embedding.