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

Free Support Forum - aspose.com

Inconsistent font usage after filling merge fields

I have a customer document containing a merge field which results in multiple fonts used after filling.
I’ve managed to narrow the template down to a single mergefield and found out this behaviour was introduced in 16.4.0.

Example snippet (java):

Document doc = Document('template.docx');
FieldMergeField field = doc.selectNodes("//FieldStart").toArray()[0].field;
field.setResult('Lorem ipsum dolor sit amet');

The words Lorem ipsum now use the Arial font, the words dolor sit amet use Times New Roman.
Before 16.4.0 all the words use the font Arial as expected.

See attached template and result before and after 16.4
This issue still exists in the latest version 17.7

mergefield-font.zip (32.5 KB)


Thanks for your inquiry. Please not that Aspose.Words mimics the same behavior as MS Word does. If you perform the mail merge using MS Word, you will get the same output.

You are facing this issue due to different font name and size in field code and result. Please set the field’s font correctly to get the desired output. You can set it using Aspose.Words. Please check the following Java code example.

Document doc = new Document(MyDir + "template.docx");
FieldMergeField field = (FieldMergeField)doc.getRange().getFields().get(0);
for (Run run : (Iterable<Run>) field.getStart().getParentParagraph().getChildNodes(NodeType.RUN, true)) {
field.setResult("Lorem ipsum dolor sit amet");
doc.save(MyDir + "result.docx");