I’m trying to remove an empty paragraph at the end of my document which is unstyled or “Normal” style. I am using Aspose.Words.for.Java 14.12.0. My code is as follows, but for some reason the paragraph still appears in the output document. See attachments. Can you please let me know what I’m doing wrong? Thanks!
private void removeLastEmptyPara() throws Exception {
// Find and remove the last empty para in document:
Document mydocument = new Document("C:\temp\filewithemptypara-input.docx");
DocumentBuilder builder = new DocumentBuilder(mydocument);
Paragraph last = mydocument.getLastSection().getBody().getLastParagraph();
if(last != null && last.getParagraphFormat().getStyleName().equals("Normal") && last.getCount() == 0){
last.remove();
}
mydocument.save("C:\temp\filewithoutemptypara-output.docx");
}