Private Fonts

Besides installed system fonts, GemBox.Presentation provides support for using private fonts and assembly fonts when saving a presentation to PDF, XPS, or image formats and when printing a presentation.

The following example shows how you can specify the location of a private or custom font (Almonte Snow.ttf) when saving a presentation to PDF.

using GemBox.Presentation;

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

        var presentation = new PresentationDocument();

        // Set the directory path where the component will look for additional font files.
        // The "." targets the current directory, so besides the installed fonts,
        // the component will be able to use the fonts within the specified directory.
        FontSettings.FontsBaseDirectory = ".";

        var slide = presentation.Slides.AddNew(SlideLayoutType.Custom);

        var textBox = slide.Content.AddTextBox(
            ShapeGeometryType.Rectangle, 2, 2, 8, 8, LengthUnit.Centimeter);

        textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray));

        var run = textBox.AddParagraph().AddRun(
            "Shows how to use private fonts with GemBox.Presentation component.");

        run.Format.Font = "Almonte Snow";
        run.Format.Size = Length.From(16, LengthUnit.Point);
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Black));

        presentation.Save("Private Fonts.%OutputFileType%");
    }
}
Imports GemBox.Presentation

Module Program

    Sub Main()

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

        Dim presentation = New PresentationDocument

        ' Set the directory path where the component will look for additional font files.
        ' The "." targets the current directory, so besides the installed fonts,
        ' the component will be able to use the fonts within the specified directory.
        FontSettings.FontsBaseDirectory = "."

        Dim slide = presentation.Slides.AddNew(SlideLayoutType.Custom)

        Dim textBox = slide.Content.AddTextBox(
            ShapeGeometryType.Rectangle, 2, 2, 8, 8, LengthUnit.Centimeter)

        textBox.Shape.Format.Outline.Fill.SetSolid(Color.FromName(ColorName.DarkGray))

        Dim run = textBox.AddParagraph().AddRun(
            "Shows how to use private fonts with GemBox.Presentation component.")

        run.Format.Font = "Almonte Snow"
        run.Format.Size = Length.From(16, LengthUnit.Point)
        run.Format.Fill.SetSolid(Color.FromName(ColorName.Black))

        presentation.Save("Private Fonts.%OutputFileType%")
    End Sub
End Module
Presentation that uses private font
Screenshot of private (not installed) font's usage

GemBox.Presentation provides the FontSettings static class where you can specify various font-related options. These options are beneficial for environments with no installed fonts (like on Docker) or where the system fonts are inaccessible and restricted (like on Medium Level Trust applications).

Assembly fonts

GemBox.Presentation supports retrieving fonts stored as resources inside the local or referenced assembly by specifying the FontSettings.FontsBaseResourceLocation property.

When you add fonts as resources to your application, make sure you're setting the Build Action as Embedded resource. Or if your application is targeting .NET Framework and thus uses WPF, set it as Resource instead.

Setting font file as embedded resource

The following image shows an example of a solution with font files added as embedded resources, and the following table illustrates the various base resource locations you can specify to use those fonts.

Packaging fonts in .NET application
Used fontFontSettings.FontsBaseResourceLocationNotes
Font1.ttf"/"Font resource files are in the root of the local assembly.
Font2.ttf"/MyFonts/"Font resource files are in the subfolder of the local assembly.
Font3.ttf"/MyClassLibrary;component/"Font resource files are in the root of the referenced assembly.
Font4.ttf"/MyClassLibrary;component/MyFonts/"Font resource files are in the subfolder of the referenced assembly.

See also


Next steps

GemBox.Presentation is a .NET component that enables you to read, write, edit, convert, and print presentation files from your .NET applications using one simple API.

Download Buy