We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Renaming bookmark - outline level accesser missing

Hi there,
We are to rename the bookmark in the word document. Our logic right now deletes the old definition and adding new bookmark at the same position. While deleting we don’t want to loose the old bookmark outline level (since we are using bookmark levels while generating (PDFs). Not seeing any access-er for outline level of bookmark. Could you please help us? Thanks for looking into this.

Hi Praneeth,

Thanks for your inquiry. You can simply rename an existing Bookmark by using the Bookmark.Name property. The following code shows how to get or set bookmark name and text.
Document doc = new Document(getMyDir() + “Bookmark.doc”);

// Use the indexer of the Bookmarks collection to obtain the desired bookmark.
Bookmark bookmark = doc.getRange().getBookmarks().get(“MyBookmark”);

// Get the name and text of the bookmark.
String name = bookmark.getName();
String text = bookmark.getText();

// Set the name and text of the bookmark.
bookmark.setText(“This is a new bookmarked text.”);

I hope, this helps.

Best regards,

This way is losing bookmarks when they are nested and overlapping. In the case, say text is “text here”, and bookmark1 lies [text], bookmark2 [te] (the part of same text), and the bookmark3 lies in [xt he], then after doing renaming of bookmark1 and 2, seeing that in output document only bookmark present is bookmark1 and all else are lost. Please look into this. Thanks.

Hi Praneeth,

Thanks for the additional information. I am afraid, I was unable to reproduce this issue on my side. Please see attached sample input/output Word documents and code from my previous post. Could you please attach your sample documents here for testing? We will investigate the issue on our end and provide you more information.

Best regards,