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

Free Support Forum - aspose.com

Only cache “common” fonts

Is there a way to tell Aspose.Words to only cache “common” fonts? and not all the special installed fonts on the machine?

@nir-1,

Are you using Aspose.Words for .NET or Aspose.Words for Java? What do you mean by common fonts? Please also elaborate your query further by providing complete details of your usecase. We will then be in better position to address your concerns accordingly.

I’m using Aspose.Net.
When converting Word document to PDF, I can see in Visual Studio, that all the fonts in my system are being loaded/accessed the first time a conversion is started - (some kind of font cache maybe?)
I’m trying to reduce the time it takes to read all the fonts, since I want just the ‘common’ fonts I need.

@nir-1,

Aspose.Words parses all the fonts available via specified font sources to properly resolve the fonts in the document. Only the information required to resolve the font (e.g. family name, style etc) is cached.

If you want to use only “common” fonts, then you can setup the font sources accordingly. Please refer to the following articles:

How to Specify True Type Fonts Location

Hope, this helps.

I’m looking for something a bit different than what you have offered:
I have a machine that has about 547 TTF and TTC files in its \windows\fonts directory.
I know in advance I will only need about 10 different fonts.
Currently, when creating a Aspose.Words.Document object and asking it to read a .DOC file, I can see it scans and caches all those fonts - this process takes time.

I need a way to tell the font cache object to read just the fonts I need. All other fonts that exists in the .DOC file will be substituted with a given default font.

How can I do that?

@nir-1,

Thanks for the additional information. We will keep you posted on further updates.

@nir-1,

As proposed earlier, please set up font sources to the 10 known fonts in the windows/fonts directory by using FolderFontSource. And to substitute all other fonts with specific default font, please set up Document.FontSettings.DefaultFontName and disable Document.FontSettings.EnableFontSubstitution flag. Hope, this helps.

I’m sorry, but I can’t figure out how to use this method to specify only 10 fonts out of all the fonts in the windows\fonts directory.
Can you please send me an example?

@nir-1,

We are working on your query and will get back to you soon.

@nir-1,

You can just create 10 FileFontSource instances with path to the required 10 fonts and pass them to FontSettings.SetFontSources method. Please check the following sample code:

Document doc = new Document("E:\\Temp\\in.docx");
            
FileFontSource defaultFont = new FileFontSource("C:\\Windows\\Fonts\\CENTURY.TTF");
FileFontSource fileFontSource1 = new FileFontSource("C:\\Windows\\Fonts\\BERNHC.TTF");
FileFontSource fileFontSource2 = new FileFontSource("C:\\Windows\\Fonts\\BRUSHSCI.TTF");
FileFontSource fileFontSource3 = new FileFontSource("C:\\Windows\\Fonts\\CASTELAR.TTF");
FileFontSource fileFontSource4 = new FileFontSource("C:\\Windows\\Fonts\\SNAP____.TTF");

doc.FontSettings = new FontSettings();
doc.FontSettings.EnableFontSubstitution = false;
doc.FontSettings.DefaultFontName = "Century";
doc.FontSettings.SetFontsSources(new FontSourceBase[] { defaultFont, fileFontSource1, fileFontSource2, fileFontSource3, fileFontSource4 });
            
doc.Save("E:\\Temp\\18.12.pdf"); 

Hope, this helps.

Thanks. It works.

The issues you have found earlier (filed as WORDSNET-17884) have been fixed in this Aspose.Words for .NET 19.1 update and this Aspose.Words for Java 19.1 update.

The issues you have found earlier (filed as WORDSNET-16496) have been fixed in this update

The issues you have found earlier (filed as WORDSNET-17876) have been fixed in this Aspose.Words for .NET 21.1 update and this Aspose.Words for Java 21.1 update.