FontRepository

FontRepository class

Performs font search. Searches in system installed fonts and standard Pdf fonts. Also provides functionality to open custom fonts.

public sealed class FontRepository

Constructors

Name Description
FontRepository() The default constructor.

Properties

Name Description
static Sources { get; } Gets font sources collection.
static Substitutions { get; } Gets font substitution strategies collection.

Methods

Name Description
static FindFont(string) Searches and returns font with specified font name.
static FindFont(string, bool) Searches and returns font with specified font name ignoring or honoring case sensitivity.
static FindFont(string, FontStyles) Searches and returns font with specified font name and font style.
static FindFont(string, FontStyles, bool) Searches and returns font with specified font name and font style ignoring or honoring case sensitivity.
static LoadFonts() Loads system installed fonts and standard Pdf fonts. This method was designed to speed up font loading process. By default fonts are loaded on first request for any font. Use of this method loads system and standard Pdf fonts immediately before any Pdf document was open.
static OpenFont(string) Opens font with specified font file path.
static OpenFont(Stream, FontTypes) Opens font with specified font stream.
static OpenFont(string, string) Opens font with specified font file path and metrics file path.
static ReloadFonts() Reloads all fonts specified by property Sources

Examples

The example demonstrates how to find font and replace the font of text of first page.

// Find font
Font font = FontRepository.FindFont("Arial");

// Open document
Document doc = new Document(@"D:\Tests\input.pdf");

// Create TextFragmentAbsorber object to find all "hello world" text occurrences
TextFragmentAbsorber absorber = new TextFragmentAbsorber("hello world");

// Accept the absorber for first page
doc.Pages[1].Accept(absorber);

// Change font of the first text occurrence
absorber.TextFragments[1].TextState.Font = font;

// Save document
doc.Save(@"D:\Tests\output.pdf"); 

See Also