Private Fonts

GemBox.Document provides the FontSettings class for specifying various font-related options used by a rendering engine when saving a document to PDF, XPS, or image formats, printing a document, or converting a document to XpsDocument or ImageSource objects.

For example, using the FontSettings.FontsBaseDirectory property you can specify the location where GemBox.Document's rendering engine can look for the document's font files. This feature is helpful for medium trust environments, like ASP.NET applications working in Medium Level Trust, where the operating system's default font directory is restricted.

The following example shows how you can specify the location of a custom font (in this case it contains the Almonte Snow.ttf font file).

Document that uses private font
Screenshot of private (not installed) font's usage
using GemBox.Document;

class Program
{
    static void Main()
    {
        // If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
        
        FontSettings.FontsBaseDirectory = ".";

        var document = new DocumentModel();

        document.DefaultCharacterFormat.FontName = "Almonte Snow";
        document.DefaultCharacterFormat.Size = 48;

        document.Content.LoadText("Hello World!");

        document.Save("Private Fonts.%OutputFileType%");
    }
}
Imports GemBox.Document

Module Program

    Sub Main()

        ' If using the Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        FontSettings.FontsBaseDirectory = "."

        Dim document As New DocumentModel()

        document.DefaultCharacterFormat.FontName = "Almonte Snow"
        document.DefaultCharacterFormat.Size = 48

        document.Content.LoadText("Hello World!")

        document.Save("Private Fonts.%OutputFileType%")

    End Sub
End Module

GemBox.Document also supports retrieving fonts stored as resources inside the local or referenced assembly by specifying the FontSettings.FontsBaseResourceLocation property. Please refer to the property's remarks section for more information on how to add and use embedded fonts.

See also


Next steps

GemBox.Document is a .NET component that enables you to read, write, edit, convert, and print document files from your .NET applications using one simple API. How about testing it today?

Download Buy