Font substitution doesn't work when saving a document as docx

Hi Aspose,


I’ve ran into difficulties trying to get certain fonts substituted when saving a document as docx.
Here is example code I’m using:

LoadOptions loadOptions = new LoadOptions();
loadOptions.setLoadFormat(LoadFormat.HTML);
Document testDoc = new Document(“file/location/test.xhtml”, loadOptions);
FontSettings.getDefaultInstance().setFontSubstitutes(“Not A Font”, “Comic Sans Pro”);
FontSettings.getDefaultInstance().setFontSubstitutes(“Symbol”, “Arial”);
testDoc.save("/tmp/test.docx");
Here is the test.xhtml file I’m loading from:

<?xml version='1.0' encoding='UTF-8' ?>

This is Courier

This is Symbol

This is Not A Font


Given that the fonts “Symbol” and “Not A Font” are not present in the file system these fonts are not substituted as expected when looking at the output, test.docx. However when saving the document as a pdf the font substitution works fine.

Hi Nolan,

Thanks for your inquiry.

FontSettings is used while rendering the document to the fixed-page format e.g. PDF, XPS etc. If you want to change the style of a Paragraph and save the document to Doc/Docx, please use ParagraphFormat.Style property to gets or set the paragraph style applied to this formatting.

Tahir Manzoor,


Thank you for your quick reply! Would this also be the case for embedding True Type Fonts in docx?
Hi Nolan,

Thanks for sharing the detail. Yes, your understanding is correct. Please note that Aspose.Words requires TrueType fonts when rendering documents to fixed-page formats (JPEG, PNG, PDF or XPS). Please refer to the following article. Hope this helps you.

How Aspose.Words Uses True Type Fonts