Private Fonts

GemBox.Spreadsheet enables you to specify the location where it should look for font files when saving a spreadsheet to PDF, XPS or image file formats, printing a spreadsheet, 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.Spreadsheet can use file system operations to retrieve font data even in Medium Trust environment.

By default, if location is not specified, GemBox.Spreadsheet 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.Collections.Generic;
3using System.Text;
4using GemBox.Spreadsheet;
5using GemBox.Spreadsheet.ConditionalFormatting;
6using GemBox.Spreadsheet.PivotTables;
7
8class Sample
9{
10    [STAThread]
11    static void Main(string[] args)
12    {
13        // If using Professional version, put your serial key below.
14        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
15
16        ExcelFile ef = new ExcelFile();
17        ExcelWorksheet ws = ef.Worksheets.Add("Private Fonts");
18
19        string pathToResources = "Resources";
20
21        FontSettings.FontsBaseDirectory = pathToResources;
22
23        ws.Parent.Styles.Normal.Font.Name = "Almonte Snow";
24        ws.Cells[0, 0].Value = "Hello World!";
25
26        ef.Save("Private Fonts.pdf");
27    }
28}
1Imports System
2Imports System.Collections.Generic
3Imports System.Text
4Imports GemBox.Spreadsheet
5Imports GemBox.Spreadsheet.ConditionalFormatting
6Imports GemBox.Spreadsheet.PivotTables
7
8Module Samples
9
10    Sub Main()
11
12        ' If using Professional version, put your serial key below.
13        SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY")
14
15        Dim ef As ExcelFile = New ExcelFile
16        Dim ws As GemBox.Spreadsheet.ExcelWorksheet = ef.Worksheets.Add("Private Fonts")
17
18        Dim pathToResources As String = "Resources"
19
20        FontSettings.FontsBaseDirectory = pathToResources
21
22        ws.Parent.Styles.Normal.Font.Name = "Almonte Snow"
23        ws.Cells(0, 0).Value = "Hello World!"
24        ef.Save("Private Fonts.pdf")
25
26    End Sub
27
28End Module

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