Custom Font

Load Custom Fonts from .TTF

Aspose.Slides lets you load fonts for rendering in presentations without even installing them. This article shows how to load fonts from custom directories without installing them. Please follow the steps below to loading Fonts from external directories by using Aspose.Slides for .NET API:

  • Create an instance of FontsLoader Class and call the static method LoadExternalFonts.
  • Perform render the presentation.
  • Clear the cache in the FontsLoader Class.

The implementation of the above is given below.

// The path to the documents directory.
string dataDir = RunExamples.GetDataDir_Text();

// folders to seek fonts
String[] folders = new String[] { dataDir };

// Load the custom font directory fonts
FontsLoader.LoadExternalFonts(folders);

// Do Some work and perform presentation/slides rendering
using (Presentation presentation = new Presentation(dataDir + "DefaultFonts.pptx"))
    presentation.Save(dataDir + "NewFonts_out.pptx", SaveFormat.Pptx);

// Clear Font Cachce
FontsLoader.ClearCache();

Get Custom Fonts Folder

A new property has been added that returns folders where font files are searched. Those are folders that have been added with LoadExternalFonts method as well as system font folders.

Specify Custom Fonts Used With Presentation

A new DocumentLevelFontSources property has been added to ILoadOptions interface. It allows to specify external fonts that are used with the presentation. Sample Code is given below.