I have a problem with deleting bookmarks & paragraphs.
Bookmarks: SUB_1 , SUB_2 , SUB_3 , SUB_4 , SUB_5 .
After loop execution, are deleted only SUB_1, SUB_3 and SUB_5 .
BookmarkCollection bookmarks = doc.getRange().getBookmarks();
DocumentBuilder builder = new DocumentBuilder(doc);
System.out.println(bookmarks.getCount());
for(Bookmark b : bookmarks) {
System.out.println("bookmark: " + b.getName());
builder.moveToBookmark(b.getName());
builder.getCurrentParagraph().remove();
}
output:
10:13:10,379 INFO [stdout] 5
10:13:10,380 INFO [stdout] (EJB default - 8) bookmark: SUB_1
10:13:10,381 INFO [stdout] (EJB default - 8) bookmark: SUB_3
10:13:10,382 INFO [stdout] (EJB default - 8) bookmark: SUB_5
You can also use bookmark.remove() method to delete bookmarks instead of moving cursor to paragraph and then removing that paragraph.
I work as developer evangelist at Aspose.
I resolve my problem. It isn't quite good, but it's work for me.
BookmarkCollection bookmarks = doc.getRange().getBookmarks();
DocumentBuilder builder;
try {
builder = new DocumentBuilder(doc);
while(bookmarks.getCount() > 0) {
for(Bookmark b : bookmarks) {
System.out.println("bookmark: " + b.getName());
b.setText("");
builder.moveToBookmark(b.getName());
builder.getCurrentParagraph().remove();
}
}
} catch (Exception e) {
e.printStackTrace();
logger.error("Problem with deleting bookmark");
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.