Private Fonts

GemBox.Document enables you to specify the location where it should look for font files when loading a document from PDF, saving a document to PDF, XPS or image file formats, printing a document, or converting it to XpsDocument or ImageSource instances as in the following sample.

This feature is especially useful for ASP.NET applications working in Medium Trust environment. By specifying a location that is under your ASP.NET application's control, GemBox.Document can use file system operations to retrieve font data even in Medium Trust environment.

By default, if location is not specified, GemBox.Document will look for font files in default font directory for the operating system.

Font file: Almonte Snow.ttf.

Screenshot

Private Fonts Screenshot

See the full code below, use RUN EXAMPLE to execute.


1using System;
2using System.IO;
3using System.Text;
4using GemBox.Document;
5
6class Sample
7{
8    [STAThread]
9    static void Main(string[] args)
10    {
11        // If using Professional version, put your serial key below.
12        ComponentInfo.SetLicense("FREE-LIMITED-KEY");
13
14        DocumentModel document = new DocumentModel();
15
16        string pathToResources = "Resources";
17
18        FontSettings.FontsBaseDirectory = pathToResources;
19
20        document.DefaultCharacterFormat = new CharacterFormat()
21        {
22            FontName = "Almonte Snow",
23            Size = 16
24        };
25
26        document.Sections.Add(
27            new Section(document,
28                new Paragraph(document, "Hello World!")));
29
30        document.Save("Private Fonts.pdf");
31    }
32}
1Imports System
2Imports System.IO
3Imports System.Text
4Imports GemBox.Document
5
6Module Samples
7
8    Sub Main()
9
10        ' If using Professional version, put your serial key below.
11        ComponentInfo.SetLicense("FREE-LIMITED-KEY")
12
13        Dim document As DocumentModel = New DocumentModel
14
15        Dim pathToResources As String = "Resources"
16
17        FontSettings.FontsBaseDirectory = pathToResources
18
19        document.DefaultCharacterFormat = New CharacterFormat() With
20        {
21            .FontName = "Almonte Snow",
22            .Size = 16
23        }
24
25        document.Sections.Add(
26            New Section(document,
27                New Paragraph(document, "Hello World!")))
28
29        document.Save("Private Fonts.pdf")
30
31    End Sub
32
33End Module

Check next sample or find out more about GemBox.Document and GemBox Software.