PdfFontCollection class
Namespace: PdfNetStack.Fonts
Assembly: PdfNetStack.dll
Package: PdfNetStack
Fonts found by family name, weight, width and style, the way CSS matches them. Add font files or directories, or use System for the fonts installed on the machine. Adding a file reads only its names and style; the font itself loads when first found. Thread safe.
public sealed class PdfFontCollectionInheritance
Examples
Section titled “Examples”PdfFont body = PdfFontCollection.System.Find("Segoe UI") ?? PdfStandardFont.Helvetica;
var fonts = new PdfFontCollection();
fonts.AddDirectory("fonts");
PdfFont? heading = fonts.Find("Inter", weight: 700);
Remarks
Section titled “Remarks”A variable font counts for every weight, width and slant its axes cover: asking for weight 650 of a family whose font has a wght axis from 100 to 900 gives the instance at 650. Its named instances are faces of the family too, and like any face can also be found by full name, such as “Inter SemiBold”.
Properties
Section titled “Properties”Families
Section titled “ Families”Family names, sorted.
public IReadOnlyList<string> Families { get; }Property Value
Section titled “Property Value”System
Section titled “ System”The fonts installed on this machine (Windows, macOS and Linux font directories), scanned on first use.
public static PdfFontCollection System { get; }Property Value
Section titled “Property Value”Methods
Section titled “Methods”Add(PdfOpenTypeFont)
Section titled “ Add(PdfOpenTypeFont)”Adds a loaded font under its family name. A variable font as loaded adds its whole design space and its named instances; an instance from GetInstance adds that one location.
public void Add(PdfOpenTypeFont font)Parameters
Section titled “Parameters”font PdfOpenTypeFont
AddDirectory(string, bool)
Section titled “ AddDirectory(string, bool)”Adds the fonts in a directory with a font extension (.ttf, .otf, .ttc, .otc, .woff, .woff2). Files that are not readable fonts are skipped, and so are directories that are missing or cannot be listed. When recursive, directories below are searched to 16 levels, without following links to directories. Returns how many fonts were added.
public int AddDirectory(string path, bool recursive = true)Parameters
Section titled “Parameters”path string
recursive bool
Returns
Section titled “Returns”AddFile(string)
Section titled “ AddFile(string)”Adds every font of a file: one, or all fonts of a collection. Returns how many were added.
public int AddFile(string path)Parameters
Section titled “Parameters”path string
Returns
Section titled “Returns”Exceptions
Section titled “Exceptions”The file is not a supported font.
Find(string, int, bool)
Section titled “ Find(string, int, bool)”The font of family closest to the requested weight and style, chosen as
CSS does (CSS Fonts 4, 5.2): for weights 400 to 500, heavier up to 500 first, then
lighter, then heavier; below 400, lighter first; above 500, heavier first. An italic is
preferred when asked for, an upright face otherwise. A variable font gives its instance at
the weight asked when its wght axis covers it. Null when the family is unknown.
public PdfOpenTypeFont? Find(string family, int weight = 400, bool italic = false)Parameters
Section titled “Parameters”family string
Family name, case insensitive, such as “Inter” or “Times New Roman”, or a face’s full name.
weight int
CSS weight, 1 to 1000: 400 regular, 700 bold.
italic bool
True to prefer an italic or oblique face.
Returns
Section titled “Returns”Find(string, PdfFontQuery)
Section titled “ Find(string, PdfFontQuery)”The font of family that best matches query, chosen as
CSS does (CSS Fonts 4, 5.2): the closest width first, then style, then weight. A variable
font gives its instance at the values found, clamped to its axes, with the query’s optical
size and variations applied over them (CSS Fonts 4, 7.2). Each location is made once, so
finding it again returns the same font. Null when the family is unknown.
public PdfOpenTypeFont? Find(string family, PdfFontQuery query)Parameters
Section titled “Parameters”family string
Family name, case insensitive, such as “Inter”, or a face’s full or PostScript name, such as “Inter SemiBold”.
query PdfFontQuery
The weight, width, style and variations wanted.