Aspose Words Java accessing TrueType Fonts on Linux

We had run into an issue where we were seeing some little boxes in place of letters on our documents when we tested the merge we are doing on the Linux box. We would run the same build on our Windows systems and there was no issue. Finally while we were trying to figure this out we determined this was a issue with the TruType fonts not being available on the Linux computer. We have looked in detail at the Aspose documentation on this and were able to make it work on the Linux computer with the FontSettings.SetFontsFolder. Now we are looking at how to deploy this with our application. One of the things mentioned is that it would be nice if we could have the ability to pick up the fonts from a jar file in the classpath? This would make it a lot easier for deploying purposes. I did see after we thought of this idea that this was suggested in this forum a while back ago and Aspose said they would look at this suggestion. This was the post https://forum.aspose.com/t/66342

. Is there any chance that Aspose has decided to implement this or will still take this into consideration? It may help like in our case we are using multiple Aspose products on the same server that will need these fonts available? Aspose Words Java and Aspose PDF Java. Please let me know if this is something that may already be supported or if this is something that may happen in the future?

Thanks,

Joe Amavisca

Hi Joe ,


Thanks for your inquiry.

We have introduced a new member named getFontsSources that gets a copy of the array that contains the list of sources where Aspose.Words looks for TrueType fonts. These font sources can be of FileFontSource, FolderFontSource, MemoryFontSource and SystemFontSource types.

You can instruct Aspose.Words to look for TrueType fonts in system folders as well as in a custom stream/byte[] object when scanning for fonts by using the following code snippet:
// 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(Arrays.asList(FontSettings.getFontsSources()));

// Add your custom font to the list.
MemoryFontSource memoryFontSource = new MemoryFontSource(your byte[] font data here);
fontSources.add(memoryFontSource);

// Convert the Arraylist of source back into a primitive array of FontSource objects.
FontSourceBase[] updatedFontSources = (FontSourceBase[]) fontSources.toArray(new FontSourceBase[fontSources.size()]);

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

I hope, this helps.