Replace bookmarks with some text

Hi,

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.

Thanks
-kapil
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.
http://www.aspose.com/docs/display/wordsjava/DocumentBuilder+Overview
http://www.aspose.com/docs/display/wordsjava/Moving+the+Cursor

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.