Empty Lines with IF condition

I attached my word template to this post.

I am trying to display customer address from xml input file. If i am getting empty string for ADDRESS_LINE2 merge field, i am seeing empty row in address. So how can i remove the empty row in result docuemnt.

I tried below option , but did not workout.

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);
doc.getMailMerge().deleteFields();

Thanks.

Hi Prashanth,


Thanks for your inquiry.

Please use the MailMerge.setCleanupOptions method as shown below to get the required output.

Hope this helps
you. Please let us know if you have any more queries.

Document doc = new Document(MyDir

  • “Address.doc”);

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS

| MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS

| MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS

| MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);

doc.getMailMerge().execute(new String[] { ..... }, new Object[] { ..... });


doc.save(MyDir + “Out.doc”);


Thanks for your quick reply.

The solution which you provided it works for me.

But may I know what is difference for those two approaches.

Thanks,

Hi Prashanth,


Thanks for your inquiry.
SPReddy:

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS);
doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);
doc.getMailMerge().deleteFields();

You are calling MailMerge.setCleanupOptions method four times with different cleanup options. The last call of this method uses MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS. This
option specifies whether unused mail merge regions should be removed from the document. So mail merge engine removes unused mail merge regions only from the document.

If you want to use multiple cleanup options, please use the MailMergeCleanupOptions with bitwise operator as shown below.


doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS

| MailMergeCleanupOptions.REMOVE_UNUSED_FIELDS

| MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS

| MailMergeCleanupOptions.REMOVE_UNUSED_REGIONS);