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

Free Support Forum - aspose.com

How to optimize FontSettings?

Hi Aspose Support,


I am using Visual C# 2012 & Aspose.Words.dll ver 13.9.0.0 in a Rest Service which generates a PDF based on several MS Word document templates.

There is need to optimize the FontSettings.

Presently, whenever a PDF is generated, we have to call FontSettings.SetFontsFolder method as shown in the example below :

FontSettings.ResetFontSources();
var sources = FontSettings.GetFontsSources();

if (sources != null)
{
var source = sources.First();
if (source != null)
{
if (source.Type == FontSourceType.SystemFonts)
{
FontSettings.SetFontsFolder(pdfPath.Replace(Constants.Output, Constants.Fonts), true);
}
}
}


Can we upload the Fonts folder in Azure Blob Storage & then access the Azure Blob Storage & pass the folder path to FontSettings.SetFontsFolder method ?

How can we cache the FontSettings at startup so that we don’t need to call FontSettings.SetFontsFolder method again each time a PDF is generated ?

Can we put the FontSettings object in Application Cache ?

Please provide code example clearly showing how we can optimize the FontSettings.

Please let me know your views on the above.

Thanks,
Vivek Gupta



Hi Sanjay,


Thanks for your inquiry. The static method FontSettings.SetFontsFolders can be used once to specify the location of TrueType fonts that Aspose.Words will use when rendering documents to PDF. You don’t need to call this method every time a new Document object is instantiated. FontSettings.SetFontsFolders loads fonts and caches them in a static cache which is shared between rendering of different documents. While setting the new location for fonts is safe at any time from any thread, it is recommended that you do not change the location of fonts while some documents might be in in the process of rendering. It is also recommended that you set the location of fonts during program startup before rendering any documents. I hope, this helps.

Best regards,