Private Fonts
Private fonts are fonts that are not installed or don’t need to be installed on the computer that executes your PDF app. 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. Private fonts can be embedded in an assembly or located in a custom directory.
GemBox.Pdf enables you to use either system or private fonts when writing text. The PdfFonts
class allows you to browse all standard, system, and private font families and font faces.
Note that GemBox.Pdf ignores the font embedding rights
. That’s why it’s the application developer's responsibility to run the font licensing rights check. In case you have any doubts, please contact the font's vendor.
The image below shows the result of the example code snippet we used to demonstrate how to write text using private fonts (Almonte Snow.ttf and almonte woodgrain.ttf). Notice that they are 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 the 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 the 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
If you need more details about assembly-embedded fonts in PDF files, check the comments of the PdfFonts.GetFontFamilies(string, string)
method and the Private Fonts GitHub example.