How to Remove Empty Paragraph after Inserting HTML into Document using Java

@Gptrnt

In the ZIP file, you shared three documents. 1) input, 2) problematic output, 3) expected output. However, In your this case you are not using input.docx. The problematic and expected output content also different.

Could you please share the expected output document for your this case? We will then provide you more information on it.

Hi,

I am attaching the expected output expected_output.docx (15.6 KB)

Thank you

@Gptrnt

You can achieve your requirement using ParagraphFormat.SpaceAfter and ParagraphFormat.SpaceBefore properties.

You do not need to modify your current code except following modified method. We have attached the output DOCX with this post for your kind reference.
output.docx (8.8 KB)

public static void insertHiddenWord(DocumentBuilder builder,String word, boolean isClosing) {
    Color dColor = builder.getFont().getColor();
    //		builder.endEditableRange+();
    builder.getFont().setHidden(true);
    String text = "|";
    if (isClosing){
        text += "/";
        builder.getCurrentParagraph().getParagraphFormat().setSpaceBefore(12.0);
    }
    text += word + "|";
    builder.getFont().setColor(new Color(0,176,80));
    builder.write(text);
    if (isClosing){

        builder.writeln();
    }
    builder.getFont().setColor(dColor);
    builder.getFont().setHidden(false);

    //		builder.startEditableRange();
}

Hi Tahir,
I have go through the code and the attached output file, as I can see space after is add in the hidden character. Actually my document view in the normal mode and it will not show the hidden character. So in normal view we can’t see the any space after the table. You can refer my expected output in which looking good in normal view (hiding the hidden character), but your output is looking congested in the table. Please help me to get the output exactly same as expected output.

Thank you

@Gptrnt

We have not found any issue with output generated by Aspose.Words. Please check the attached screenshots of documents.

output generated by Aspose.Words.jpg (168.0 KB)
expected output.jpg (165.5 KB)

Moreover, in your expected output document, you set the table text wrapping to ‘Around’. In this case, you need to set the table position.
Table Text Wrapping Around.jpg (179.4 KB)
Instead of setting table position, we suggest you please set the paragraph space after and before.

So, if the paragraph space after or before is not according to your requirement you can increase or decrease it according to your requirement using ParagraphFormat.SpaceBefore and ParagraphFormat.SpaceAfter properties. Hope this answer your query.