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

Free Support Forum - aspose.com

Using html code in a field with IF statement

Hi Folks,

I have a field with an HTML code it renders only if the field is not a result of IF statement.

The content of this field is:html-code.png (1.6 KB)

Anyone knows why? In the template i am printing the field 3 times just to show whats happening.

Here we have the template with the expressions:
Template.png (8.7 KB)

Here we have the aspose result:
Aspose-result.png (5.9 KB)

Thank you!


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Hi @tahir.manzoor,

I did a small example the input and output also included.

aspose-test.zip (60.1 KB)

I will try to understand it… but if someone help me i really appreciate.

Thank you.


Thanks for sharing the detail. We have tested the scenario using latest version of Aspose.Words for Java 18.4 with following code example and have not found the shared issue. Please use Aspose.Words for Java 18.4. We have attached the output DOCX with this post for your kind reference. 18.4.zip (13.8 KB)

Document doc = new Document(MyDir + "input.docx");

doc.getMailMerge().setFieldMergingCallback(new MyFieldMergingCallback_175624());
doc.getMailMerge().execute(new String[] {"OV_ALG_tekst_afwijking"}, new String[] {"<font style=\"font-family:Arial;font-size:13px;\"><p>Some html value as an example...</p></font>"});

doc.save(MyDir + "18.4.docx", SaveFormat.DOCX);

public class MyFieldMergingCallback implements IFieldMergingCallback {

    public void fieldMerging(final FieldMergingArgs args) throws Exception {
        //HTML formatteren in mergefield
        if (args.getFieldValue() != null)
            // Insert the text for this merge field as HTML data, using DocumentBuilder.
            DocumentBuilder builder = new DocumentBuilder(args.getDocument());
             builder.moveToMergeField(args.getDocumentFieldName(), true, false);
            builder.insertHtml(args.getFieldValue().toString(), true);

    public void imageFieldMerging(final ImageFieldMergingArgs imageFieldMergingArgs) throws Exception {


Hi @tahir.manzoor

It works only with 18.4 with our version 14.11.0 is not working.

I am gonna check with our team what to do.

Thank you for your support!

Dennys Fredericci


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.


Maybe we move forward to upgrade the aspose.

Do you know how it works? I am not sure if its possible to use the aspose 18.4 version with the actual license.

Thank you.


Thanks for your inquiry. Please check the expiration date of your license file. To check an expiration date of your license, open the license file using notepad. You will see the following tags:


It means that you can free upgrade to version of Aspose product published before 05/31/2018.

If you need to upgrade to the latest version of Aspose.Words, but your license does not allow you to upgrade to this version, please post your query in Aspose.Purchase forum to renew your license.