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

Free Support Forum - aspose.com

Conditional Mergefields containing a table as result: empty lines are added before and/or after the results

Dear Aspose Team,

With {IF … } Mergefields we can display some info depending on some mergefields values.
Example: I have a list of orders and I only display the VIP customer addresses with something like that:

{IF {MERGEFIELD customerType } = “VIP” {MERGEFIELD address } }

It works fine.
If we insert the {MERGEFIELD address} into a table which is inside this IF mergefield, we get a lot of space between each address-entry.

I have attached a small maven project that illustrates this problem. It is very easy to use: there are only 2 classes.
- one for creating dummy data
- one for creating the pdf. It has a main method, just run it and you will get the report.pdf in your temp directory.
The template (docx) is in the project resources directory.
As you will see using the MailMergeCleanupOptions does not help here. Do we make something wrong?

Thanks in advance

Hi Emmanuel,

Thanks for your inquiry. I have tested the scenario and notice the empty line issue. I am further investigating the issue and will update you soon.

Best Regards,

Hi Emmanuel,

Thanks for your patience. You may remove the empty paragraphs as following. Hopefully it will help you to accomplish the task.



// Remove Empty paragraphs

for (Paragraph paragraph : (Iterable) doc.getChildNodes(

NodeType.PARAGRAPH, true)) {

// Get next node after the paragraph.

CompositeNode nextNode = (CompositeNode) paragraph.getNextSibling();

// If paragraph is empty and the next node is also enpty paragraph,

// remove the paragraph.

if (!paragraph.hasChildNodes() && nextNode != null

&& !nextNode.hasChildNodes()) {






Best Regards,