Available for: UI for ASP.NET MVC | UI for ASP.NET AJAX | UI for Blazor | UI for WPF | UI for WinForms | UI for Silverlight | UI for Xamarin | UI for WinUI | UI for ASP.NET Core | UI for .NET MAUI

New to Telerik Document Processing? Download free 30-day trial

Fonts

RadPdfProcessing uses fonts represented by FontBase objects to specify the look of the text that is exported to PDF. Currently, it supports two font types: Standard and Embedded.

Standard Fonts

There are 14 standard fonts that are not embedded in the document when you use them. These fonts can be accessed through the FontsRepository class and are listed below.

  • Helvetica
  • Helvetica-Bold
  • Helvetica-Oblique
  • Helvetica-BoldOblique
  • Courier
  • Courier-Bold
  • Courier-Oblique
  • Courier-BoldOblique
  • Times-Roman
  • Times-Bold
  • Times-Italic
  • Times-BoldItalic
  • Symbol
  • ZapfDingbats

Embedded Fonts

All fonts, which are not included in the 14 standard ones should be embedded in the PDF document. Otherwise, the result when the document is rendered is unpredictable. In RadPdfProcessing you have the ability to embed fonts following the approaches described below.

If you do not wish to embed the fonts in the document set the ShouldEmbedFonts property of the ExportSettings.

Registering a Font

If you want to use a font, which is not part of the standard ones, you can register it using the RegisterFont() method of the FontRepository static class. The method requires four parameters - FontFamily, FontStyle and FontWeight objects describing the font and a byte array containing the raw font data.

Example 1 demonstrates how you can use the RegisterFont() method.

Example 1: Register font in .NET Framework application

// Read the font file 
byte[] fontData = File.ReadAllBytes("some-font.ttf"); 
System.Windows.Media.FontFamily fontFamily = new System.Windows.Media.FontFamily("Some Font"); 
 
// Register the font 
 Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(fontFamily, System.Windows.FontStyles.Normal, System.Windows.FontWeights.Normal, fontData); 

Example 1: Register font in .NET Standard application

// Read the font file 
byte[] fontData = File.ReadAllBytes("some-font.ttf"); 
Telerik.Documents.Core.Fonts.FontFamily fontFamily = new Telerik.Documents.Core.Fonts.FontFamily("Some Font"); 
 
// Register the font 
 Telerik.Windows.Documents.Fixed.Model.Fonts.FontsRepository.RegisterFont(fontFamily, Telerik.Documents.Core.Fonts.FontStyles.Normal, Telerik.Documents.Core.Fonts.FontWeights.Normal, fontData); 

Creating a Font

Each registered font can be obtained from the font repository as FontBase object and applied to a TextFragment through its Font property.

Example 2 shows how to create a font using the FontsRepository.

Example 2: Create FontBase

FontBase font; 
bool success = FontsRepository.TryCreateFont(fontFamily, fontStyle, fontWeight, out font); 

You can create fonts that are not explicitly registered. Creating a font that is not registered in the repository with the code from Example 2 tries to find the font from the ones installed on the machine.

Note that due to security limitations in Silverlight, creating a font that is not present in the repository with the code from Example 2 is going to fail - the application doesn't have the permissions to get the font from the file system.

See Also

In this article