Conversion it is leaving empty line for each- if condition evaluation result to false

As part of POC for converting doc/docx to PDF we started considering Aspose Word API (Java).
hi,

As part of POC for converting doc/docx to PDF we started considering Aspose Word API (Java).
When we are inserting conditional evaluation in word document like below, during the conversion it is leaving empty line for each if condition evaluation result to false, can you please ask your team to help me out:

Hi Irfan,

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

  • Your input Word document
  • Aspose.Words generated output DOCX file showing the undesired behavior
  • Please attach your expected document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using Microsoft Word.
  • Please create a standalone Java application (source code without compilation errors) that helps us 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 code to achieve the same by using Aspose.Words. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,

Hi.
I attached input document and output document (after applying aspose) and highlighted the issue in red color in output document.
This is very urgent, kindly work on the POC immediately…
thx.
M.Irfan.

Hi Irfan,

Thanks for your inquiry. You can remove LineBreak Run nodes by using the following code:

Document doc = new Document("D:\temp\InputDoc.docx");

doc.getMailMerge().setCleanupOptions(MailMergeCleanupOptions.REMOVE_EMPTY_PARAGRAPHS |
MailMergeCleanupOptions.REMOVE_CONTAINING_FIELDS);

doc.getMailMerge().execute(new String[] { "FORM_NAME", "WORK_STATE" },
new Object[] { "SAMPLEFORM", "AP" });

for (Run run : (Iterable)doc.getChildNodes(NodeType.RUN, true))
{
    if (run.getText().equals(ControlChar.LINE_BREAK))
    {
        run.remove();
    }
}

doc.save("D:\temp\awjava-17.2.0.docx");

Hope, this helps.

Best regards,