FontRepository.OpenFont
Contents
[
Hide
]OpenFont(Stream, FontTypes)
Opens font with specified font stream.
public static Font OpenFont(Stream fontStream, FontTypes fontType)
Parameter | Type | Description |
---|---|---|
fontStream | Stream | Font stream. |
fontType | FontTypes | Font 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
- class Font
- enum FontTypes
- class FontRepository
- namespace Aspose.Pdf.Text
- assembly Aspose.PDF
OpenFont(string)
Opens font with specified font file path.
public static Font OpenFont(string fontFilePath)
Parameter | Type | Description |
---|---|---|
fontFilePath | String | Font 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
- class Font
- class FontRepository
- namespace Aspose.Pdf.Text
- assembly Aspose.PDF
OpenFont(string, string)
Opens font with specified font file path and metrics file path.
public static Font OpenFont(string fontFilePath, string metricsFilePath)
Parameter | Type | Description |
---|---|---|
fontFilePath | String | Font file path. |
metricsFilePath | String | Font 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
- class Font
- class FontRepository
- namespace Aspose.Pdf.Text
- assembly Aspose.PDF