Private Fonts

GemBox.Document provides the FontSettings class for specifying various font related options which are 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 especially useful for medium trust environments, like ASP.NET applications working in Medium Level Trust, where accessing the default font directory for the operating system 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 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 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 that are stored as resources inside the local or referenced assembly by specifying the FontSettings.FontsBaseResourceLocation property. Note; under this property's remarks you can find out how you can use embedded fonts.

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Document yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.