FontSettingsSetFontsSources Method

Sets the sources where Aspose.Words looks for TrueType fonts when rendering documents or embedding fonts.

Namespace:  Aspose.Words.Fonts
Assembly:  Aspose.Words (in Aspose.Words.dll) Version: 20.8.0

Syntax

public void SetFontsSources(
	FontSourceBase[] sources
)

Parameters

sources
Type: Aspose.Words.FontsFontSourceBase
An array of sources that contain TrueType fonts.

Remarks

By default, Aspose.Words looks for fonts installed to the system.

Setting this property resets the cache of all previously loaded fonts.

Examples

Demonstrates how to set Aspose.Words to look for TrueType fonts in system folders as well as a custom defined folder when scanning for fonts.
Document doc = new Document(MyDir + "Rendering.docx");

// Retrieve the array of environment-dependent font sources that are searched by default
// For example this will contain a "Windows\Fonts\" source on a Windows machines
// We add this array to a new ArrayList to make adding or removing font entries much easier
ArrayList fontSources = new ArrayList(FontSettings.DefaultInstance.GetFontsSources());

// Add a new folder source which will instruct Aspose.Words to search the following folder for fonts
FolderFontSource folderFontSource = new FolderFontSource("C:\\MyFonts\\", true);

// Add the custom folder which contains our fonts to the list of existing font sources
fontSources.Add(folderFontSource);

// Convert the ArrayList of source back into a primitive array of FontSource objects
FontSourceBase[] updatedFontSources = (FontSourceBase[]) fontSources.ToArray(typeof(FontSourceBase));

// Apply the new set of font sources to use
FontSettings.DefaultInstance.SetFontsSources(updatedFontSources);

doc.Save(ArtifactsDir + "Rendering.SetFontsFoldersSystemAndCustomFolder.pdf");

See Also