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

Free Support Forum - aspose.com

Conditional merge field doesn't work with picture


We tried to merge fields which contains image. If there isn’t conditionnal on Word document, it works fine.Problem occurs when we add conditional in (like IF or COMPARE)
Conditionnals work on field of type text but seem to be harder to apply on picture.

Sometimes picture is duplicated, sometimes it appeared and sometimes not, regardless of the applied condition.

I added a template to this post.

Version Aspose word used: 11.0.0 but we have 11.10.0 (soon tested by users).

This two versions don’t work!

Thank you very much for your answer.
Best regards,

Not solved in 13.1.0 too…


Thanks for your inquiry. Could you please also attach the piece of code causing this problem along with the output Word document (that is produced on your side) and your expected Word document here for testing? Once I have these resources, I will investigate the issue on my side and provide you more information.

PS: You can create the expected document using Microsoft Word. We just want to see as to how you want your final output to be generated like.

Best regards,


I attach one file named MERGEFIELDS_TEST1_TEST2.txt containing datas to merge in word document (datas with names and values for test n°1 and datas with names and values for test n°2).
Think about a real picture with streamed datas instead of value: “PictureStream”.

The output Word documents (that are produced on my side) are attached with
name “result test 1.docx” and “result test 2.docx”.

The output Word documents i expected are attached too named “result test 1 expected.docx” and “result test 2 expected.docx”.

I attached a new template: “image fields test.docx”

Thx a lot for your investigation.

Best regards,

Hi Pierre,

Thanks for the additional information.

While using the latest version of Aspose.Words for .NET i.e. 13.1, I was unable to reproduce this issue on my side. Could you please double check if you’re using Aspose.Words 13.1 on your side?

You can dynamically check if you’re referencing the correct DLL by using the following code snippet:

System.Reflection.Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
foreach (System.Reflection.Assembly assembly in assemblies)
    System.Reflection.AssemblyName assemblyName = assembly.GetName();
    if (assemblyName.Name.Contains("Aspose.Words"))
        Console.WriteLine("Aspose.Words Version Number: " + assemblyName.Version.ToString());

In case you’re using an older version, I would suggest you please upgrade to the latest version of Aspose.Words. You can download it from the following link:

Moreover, I have attached a couple of output documents, i.e. generated on my side using the following code snippet, here for your reference.

Document doc = new Document(@"C:\Temp\image+fields+test.docx");
// test case 1
// new object[] { "Pierre", "Pierre", @"C:\Temp\image1.jpeg", "Pierre", @"C:\Temp\image1.jpeg", "Pierre", @"C:\Temp\image1.jpeg", "Pierre", @"C:\Temp\image1.jpeg", "Pierre", @"C:\Temp\image1.jpeg", "Pierre", "Pierre", "Pierre", "Pierre" });
// test case 2
new object[] { "Danièle", "Danièle", @"C:\Temp\image1.jpeg", "Danièle", @"C:\Temp\image1.jpeg", "Danièle", @"C:\Temp\image1.jpeg", "Danièle", @"C:\Temp\image1.jpeg", "Danièle", @"C:\Temp\image1.jpeg", "Danièle", "Danièle", "Danièle", "Danièle" });
doc.Save(@"C:\temp\out test2.docx");

If we can help you with anything else, please feel free to ask.

Best regards,


I used Aspose word for java 11.0.0 for the previous test, but the 11.10.0 and 13.1.0 give us approximately the same problem.

I’ve tested on 13.1.0 aspose word java.
I attached my source code and the results and the expected results.

Thx u.

Hi Pierre,

Thanks for the additional information. Could you please also attach complete code of the class InsertDocumentAtMailMergeHandler which implements the methods IFieldMergingCallback.FieldMerging and IFieldMergingCallback.ImageFieldMerging here for testing.

Many thanks,

I attached.


Hi Pierre,

Thanks for the additional information. I have attached two sets of resources (containing the output documents produced on my side with Aspose.Words 13.1: see out.docx documents) here for your reference. Could you please execute the simplified Java codes (see test1-simplified.txt & test2-simplified.txt) and let me know of your findings.

Best regards,


With the simplified test 1 and 2, it works fine.
It permit to us to detect the real problem which do that.

It seems to be the line:

FieldsHelper.convertFieldsToStaticText(doc, FieldType.FIELD_IF);

But this line is very important, if i don’t do that, another problem occurred whatever the version of Aspose word.
We need to render a static document because of users which write in, can write in mergefields or conditionnal field not visible…it seems to work but when we convert in pdf file, their writed text disappeared.

I explain:
Take a look at the file i attached named: “test.doc”

It’s one of result doc from a merge by aspose word, it contain “conditionnal if”, and when user write in, to change text or date for exemple to this line "Les
travaux devront démarrer le 15/02/2013.
Leur délai d’exécution est de 12
. I save this doc and i update fields with updateFields method to update dates in document(we have to know in document when the doc is convert in pdf), then i convert it to pdf file with Aspose.
The problem is: the modified text in the conditionnal field are not taken into account because of updateFields before convert into pdf and we need to update some fields.

May be it exist a methode updateFields(FieldType type) with type as FieldType.FIELD_DATE…
But i don’t find, that’s why i used convertFieldsToStaticText on FieldType like FIELD_IF after merge.

If you have some questions…
Thx you.

Hi Pierre,

Thanks for the additional information.

You can work around this problem by adding an additional VisitorAction operation to the FieldsHelper class that is called each time a Shape node is encountered in the document. You can then remove the extra Shape from within the body of that operation. Please see the following code:

public int visitShapeStart(Shape shape) {
    // Remove the Shape if it is between the FieldStart and FieldSeparator of
    // the field being converted.
    return VisitorAction.CONTINUE;

I hope, this helps.

Best regards,

It seems to be good!
Very nice job

We’ll try with more test…see you soon.


Hi Pierre,

Thanks for your feedback on this. Please let us know any time you have any further queries. We are always glad to help you.

Best regards,

Problem solved
Thx u