We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Embed Fonts in AzureFunctions for Aspose to render the PDFs correctly

I want to embed Fonts in the AzureFunctions to avoid embedding the fonts in every Word Document which is processed with Aspose to PDF. The fonts are embedded in the azure functions and loaded before a Word Document is rendered to PDF. We don’t want to load every font every time whenever we want to render a PDF. Is there any possibility to only set the fonts globally and Aspose is loading it when it needs to?
How to achieve this?

@PCP808 Aspose.Words need to parse all available fonts in order to get information required for font resolving. This search information is cached per FontSettings instance. But as I understand in AzuerFunctions FontSettings instance may not be preserved. There is an option to save and load this search information into an XML file. This should help in your case. Please check Save and Load a Font Search Cache article for more info. Please feel free to ask if you will have more questions.

@Konstantin.Kornilov:- So first load the custom fonts from a folder & than use the font search cache for subsequent usage Please confirm?. How to save & load this search information into an XML file

@PCP808 Yes, your are right. First you need to set up font sources in your environment and save the font search cache. It should be done one time when preparing your environment.

fontSettings.SetFontSources(yourSources);
fontSettings.SaveSearchCache(searchCacheStream);

Later, when performing the conversion, you should set up the font sources the same way it was done when saving cache and specify the cache:

fontSettings.SetFontSources(yourSources, seachCacheStream);

Also to improve the performance you could try to preserve the FontSettings instance between conversions calls if AzureFunctions allow this.

Please note that it is highly recommended to provide the same font sources when loading cache as at the time the cache was saved. Any changes in the font sources (e.g. adding new fonts, moving font files or changing the cache key) may lead to the inaccurate font resolving by Aspose.Words.

How to save & load this search information into an XML file ?

@PCP808 You could provide a FileStream for an XML file as a searchCacheStream in a code sample.

Any sample code?

@PCP808 Save font search cache to file:

FontSettings settings = new FontSettings();
settings.SetFontsSources(yourSources);
using (var fileStream = File.Create(pathToXmlFile))
    settings.SaveSearchCache(fileStream);

Load font search cache from file:

FontSettings settings = new FontSettings();
using (var fileStream = File.OpenRead(pathToXmlFile))
    settings.SetFontsSources(yourSources, fileStream);