Free Support Forum -

How remove or make invisible merge field with no merged data

We generate word documents using Aspose Word with Photos of persons we have taken photos of at an event, for example graduation.

Some events just have one pose, others have 2 pose (thus two photos), etc. So we have templates that hold 1 photo, 2 photos, 3 photos, etc. Occasionally a person does not have as many photos as there are images place holders.

How do we remove or make invisible a merge field in which there is no merge data. The same concept would apply to an Address2 merge field if there were no address 2.


Have you tried MailMerge.DeleteFields method? It clears unused mergefields from the document.

Sometimes, empty lines are still left in the document even after that. If this will be the case, then send me your template and I will try to compose a code snippet specifically adapted for it.