Existing bookmarks not overridden - DocumentBuilder.moveToEnd()

Hi there,
If the bookmarks are present in word document and we try to add a bookmark with same name it should be overridden (the last one should persist), right?

We have a document with existing bookmarks and our goal is to insert bookmarks at start and end.

Now, when we move to start using DocumentBuilder.moveToStart() and tries to insert the bookmark with same named bookmark which is already present in the doc, it overrides those. That’s what we want.

But problem is when we move to end using DocumentBuilder.moveToEnd() and then tries to insert the bookmark with same named bookmark which is already present in doc, they not got overridden and previous one persisted.

Attaching a doc which has - {start_db_frcs_doclet, docletBookmark, anotherDocletBookmark} bookmarks.

And we are inserting bookmark like this-
Document doc1 = new Document(testBookmark.docx);
DocumentBuilder builder = new DocumentBuilder(doc1);
builder.moveToDocumentEnd(); // builder.moveToDocumentStart();
String bookmark =“start_db_frcs_doclet”;
addBookmark(builder, bookmark);

bookmark =“docletBookmark”;
addBookmark(builder, bookmark);

bookmark =“anotherDocletBookmark”;
addBookmark(builder, bookmark);

The behavior we expect is when we insert at end existing bookmarks already present in document should be vanished and our bookmarks at our place should be inserted.

Please look into this.

PS: the addBookmark thing is -
static void addBookmark(DocumentBuilder builder, String bookmarkName) {
builder.startBookmark(bookmarkName);
// No text inside the bookmark
builder.endBookmark(bookmarkName);
}

Hi Praneeth,


Thanks for your inquiry. It is by Microsoft Word design that a Word document must have unique names for bookmarks. You can not insert two bookmarks with the same names. In your case, before adding a new bookmark, you can check whether a bookmark with same name is already present in document. If yes, you can first remove the existing bookmark from document and add new one at a new location. I hope, this helps.

Best regards,

Hi Awais,
Thanks for reply.

Just curios how Aspose overwrites the existing named bookmark when we add a bookmark at beginning of document but could not in case when we add a bookmark at end of the document.

Hi Praneeth,


Thanks for your inquiry. I have logged this problem in our issue tracking system as WORDSNET-9828. Our development team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi Praneeth,


Thanks for being patient. Regarding WORDSNET-9828, our development team has completed the analysis of this issue and has come to a conclusion that this issue and the undesired behaviour you’re observing is actually not a bug in Aspose.Words. So, we will most likely close this issue as ‘Not a Bug’.

Before saving a document, Aspose.Words runs validation process and during validation Aspose.Words removes nodes of bookmarks with duplicate names and removes bookmarks that have no matching start or end node. So, let’s imagine you inserted duplicated bookmarks at the beginning of the document, in this case validator will start visiting document from the beginning and find first bookmark at the beginning of the document, this bookmark will be considered as the first one with unique name. Then your original bookmark (at the middle of the document) will be visited and it is considered as duplicate which will then be removed.

In case when the bookmark with duplicate name is inserted at the end of the document, validator firstly finds original bookmark and then bookmark with duplicate name (which will be removed).

Best regards,

The issues you have found earlier (filed as ) have been fixed in this update. This message was posted using BugNotificationTool from Downloads module by MuzammilKhan