Private Fonts
GemBox.Pdf enables you to use either system or private fonts when writing text.
Private fonts can be located either in a custom directory or embedded in an assembly. Using private fonts is required in restricted environments, such as ASP.NET applications working in Medium Level Trust where accessing the default font directory for the operating system is not allowed.
Additionally, the PdfFonts
class enables you to browse all standard, system, and private font families and font faces.
The following example shows how to write text using private fonts (Almonte Snow.ttf and almonte woodgrain.ttf) located in the same directory as the application.

using System.Linq;
using GemBox.Pdf;
using GemBox.Pdf.Content;
class Program
{
static void Main()
{
// If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY");
using (var document = new PdfDocument())
{
var page = document.Pages.Add();
using (var formattedText = new PdfFormattedText())
{
formattedText.FontSize = 48;
formattedText.LineHeight = 72;
// Use the font family 'Almonte Snow' whose font file is located in the same directory as the application.
formattedText.FontFamily = new PdfFontFamily(null, "Almonte Snow");
formattedText.AppendLine("Hello World 1!");
// Use the font family 'Almonte Woodgrain' whose font file is located in the same directory as the application.
formattedText.FontFamily = new PdfFontFamily(null, "Almonte Woodgrain");
formattedText.AppendLine("Hello World 2!");
// Another way to use the font family 'Almonte Snow' whose font file is located in the same directory as the application.
formattedText.FontFamily = PdfFonts.GetFontFamilies(null).First(ff => ff.Name == "Almonte Snow");
formattedText.AppendLine("Hello World 3!");
// Another way to use the font family 'Almonte Woodgrain' whose font file is located in the same directory as the application.
formattedText.FontFamily = PdfFonts.GetFontFamilies(null).First(ff => ff.Name == "Almonte Woodgrain");
formattedText.Append("Hello World 4!");
page.Content.DrawText(formattedText, new PdfPoint(100, 500));
}
document.Save("Private Fonts.%OutputFileType%");
}
}
}
Imports System.Linq
Imports GemBox.Pdf
Imports GemBox.Pdf.Content
Module Program
Sub Main()
' If using Professional version, put your serial key below.
ComponentInfo.SetLicense("FREE-LIMITED-KEY")
Using document = New PdfDocument()
Dim page = document.Pages.Add()
Using formattedText = New PdfFormattedText()
formattedText.FontSize = 48
formattedText.LineHeight = 72
' Use the font family 'Almonte Snow' whose font file is located in the same directory as the application.
formattedText.FontFamily = New PdfFontFamily(Nothing, "Almonte Snow")
formattedText.AppendLine("Hello World 1!")
' Use the font family 'Almonte Woodgrain' whose font file is located in the same directory as the application.
formattedText.FontFamily = New PdfFontFamily(Nothing, "Almonte Woodgrain")
formattedText.AppendLine("Hello World 2!")
' Another way to use the font family 'Almonte Snow' whose font file is located in the same directory as the application.
formattedText.FontFamily = PdfFonts.GetFontFamilies(Nothing).First(Function(ff) ff.Name = "Almonte Snow")
formattedText.AppendLine("Hello World 3!")
' Another way to use the font family 'Almonte Woodgrain' whose font file is located in the same directory as the application.
formattedText.FontFamily = PdfFonts.GetFontFamilies(Nothing).First(Function(ff) ff.Name = "Almonte Woodgrain")
formattedText.Append("Hello World 4!")
page.Content.DrawText(formattedText, New PdfPoint(100, 500))
End Using
document.Save("Private Fonts.%OutputFileType%")
End Using
End Sub
End Module
Private fonts can also be embedded in an assembly. For more details about assembly-embedded font files, see the remarks of the PdfFonts.GetFontFamilies(string, string)
method and the Private Fonts GitHub example.