Free Support Forum - aspose.com

Font Substitution from specific directory

Hi,
I can substitute a missing font with another one … but only with another one which is located in the windows system font directory.

how can i substitute with fonts located in a specific directory ?
Thanks in advance.

@tparassin,

Thanks for your inquiry. First, you need to set the font sources as shown below and than apply font substitution. Hope this helps you.

// 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);

ok, it’s fine now.
Thank you for your help.

What’s the difference between

  • working on the FontSettings.DefaultInstance
  • creating a FontSettings fontSettings, working on it and setting doc.FontSettings = fontSettings

?

@tparassin

Thanks for your inquiry. Both properties work the same. The only difference between these properties is FontSettings.DefaultInstance uses static default font settings and other property does not. By default, all documents use single static font settings instance.

If you create the instance of FontSettings class, you need to assign it to Document.FontSettings to get it work.