FontRepository.OpenFont

OpenFont(Stream, FontTypes)

Opens font with specified font stream.

public static Font OpenFont(Stream fontStream, FontTypes fontType)
ParameterTypeDescription
fontStreamStreamFont stream.
fontTypeFontTypesFont type value.

Return Value

Font object.

Examples

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

// Open font
using (FileStream fontStream = File.OpenRead(@"C:\WINDOWS\Fonts\arial.ttf"))
{
    Font font = FontRepository.OpenFont(fontStream, , FontTypes.TTF);

    // 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


OpenFont(string)

Opens font with specified font file path.

public static Font OpenFont(string fontFilePath)
ParameterTypeDescription
fontFilePathStringFont file path.

Return Value

Font object.

Examples

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

// Open font
Font font = FontRepository.OpenFont(@"C:\WINDOWS\Fonts\arial.ttf");

// 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


OpenFont(string, string)

Opens font with specified font file path and metrics file path.

public static Font OpenFont(string fontFilePath, string metricsFilePath)
ParameterTypeDescription
fontFilePathStringFont file path.
metricsFilePathStringFont metrics file patrh.

Return Value

Font object.

Examples

The example demonstrates how to open Type1 font with metrics and replace the font of text of first page.

// Open font
Font font = FontRepository.OpenFont("courier.pfb", "courier.afm");

// 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