I am using Aspose Words for Java 17.3.0. I have a docx document which has 2 bookmarks, which share the same name.
I bumped into issue with removal of these bookmarks. Looks like library is unable to identify BookmarkEnd elements for both bookmarks correctly. They both refer to single BookmarkEnd element, which is wrong. Exception is thrown, when I remove bookmarkEnd element of second bookmark as a result.
Exception in thread “main” java.lang.IllegalStateException: Cannot remove because there is no parent.
at com.aspose.words.Node.remove(Unknown Source)
Needless to say that this is causing problems to our customers.
Code snippet to reproduce this below (file attached):
final String inputFile = INPUT_FOLDER + “bookmark_problem.docx”;
License license = new License();
Document document = new Document(inputFile);
BookmarkCollection bookmarks = document.getRange().getBookmarks();
System.out.println("Amount of bookmarks: " + bookmarks.getCount());
BookmarkStart start1 = bookmarks.get(0).getBookmarkStart();
BookmarkStart start2 = bookmarks.get(1).getBookmarkStart();
BookmarkEnd end1 = bookmarks.get(0).getBookmarkEnd();
BookmarkEnd end2 = bookmarks.get(1).getBookmarkEnd();
System.out.println(“BookmarkEnd1:” + end1);
System.out.println(“BookmarkEnd2:” + end2);
bookmark_problem.zip (10.8 KB)