Remove bookmark -How to remove empty line (row) inside bookmark?

Hi aspose support,
I use aspose in word to remove some bookmark by using some code bellow:

Document doc = new Document(MyDir + “in.docx”);
Bookmark bookmark = doc.getRange().getBookmarks().get(“AsposeBookmark”);
bookmark.setText("");
bookmark.remove();
doc.save(MyDir + “out.docx”);

The bookmark is removed but still have a new line (row) of it. How to remove this line?

Thanks!

@baogq,

The following Aspose.Words code should help you to achieve the desired output:

Document doc = new Document("E:\\temp\\in.docx");

Bookmark bookmark = doc.getRange().getBookmarks().get("bookmark");
bookmark.setText("");
Paragraph para = (Paragraph) bookmark.getBookmarkStart().getAncestor(NodeType.PARAGRAPH);
if (para != null && para.toString(SaveFormat.TEXT).trim().equals("")) {
    bookmark.remove();
    para.remove();
}

doc.save("E:\\temp\\19.10.docx");