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

Free Support Forum - aspose.com

Replace bookmarks with some text


we have a requirement to replace the bookmark text with bookmarkText.

if “bookMark Text” is a bookmark in document, then i want to replace it with “bookmark Text” and remove the bookmark.

how can i achieve this requirement with aspose. suggest me.

Hi Kapil,

Thanks for your inquiry. In your case, I suggest you following solution.

1) Get the bookmark using Range.Bookmarks property.

Bookmark bookmark = doc.getRange().getBookmarks().get("bookmarkName");

2) If bookmark is not null, move the cursor to the bookmark location using DocumentBuilder.moveToBookmark method

3) Remove the bookmark using Bookmark.remove method and insert the contents using DocumentBuilder.write method

Please read following documentation links for your kind reference.

Hope this helps you. If you still face problem, please share the input and expected output documents here for our reference. We will then provide you more information about your query along with code.

thank you for your solution, it’s worked form me.

Hi Kapil,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.