Setting fonts as resources or input streams

Hello,


Is it possible to set fonts for Aspose.Words as resources or input streams?
The problem that our fonts are stored inside war-archive and these fonts do not have physical file folders which Aspose can take in FontSettings.

Best regards, Evgeniy

Hi Evgeniy,


Thanks for your inquiry. I am in communication with our development team and will update you as soon as I have information on this topic.

PS: Aspose.Words supports Embedded TrueType fonts. This means you can use TrueTypes fonts embedded into the template you are using for generating documents.

Best regards,

Hi Awais,


Could you communicate with the development team and discuss the topic?

Regarding “Embedded fonts” - thank you, I know the feature, but it cannot help me completely.
I need to add fonts dynamically and cannot store the fonts indide the document template.

I see two possible variants:
1) New method addFont(InputStream inputStream) or addFont(byte[] bytes) to have possibility to add font from any location.

2) To use Spring-notation to define resources location.
file:C:/Windows/Fonts
classpath:com.mycompany.fonts
In the second case “com.mycompany.fonts” is not a physical path in filesystem but the resource path which can be used by a classloader.

Best regards, Evgeniy

Hi Evgeniy,


Thanks for the additional information. I have passed your suggestions to our development team. I will update you as soon as I have any information about it.

Best regards,

Hi Evgeniy,


Thanks for being patient. 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.

Best regards,

Hi Awais,


Thank you very much for the code sample!

Best regards, Evgeniy