Can I add 2 different bookmark around the same range of text in a document in a word doc through code?

Hi,

I want to add 2 different bookmarks with 2 different names to be used for different purposes around the same text in a word document. I am aware this is possible through word manually.

Is it possible to do this through code?

Below is a code snippet I tried but could’nt achieve the desired output. Is it possible to do this? Or is there a better way to achieve this somehow? A better refactored code? Am I doing something wrong?

 Document doc = new Document();
 DocumentBuilder builder = new DocumentBuilder(doc);
 builder.startBookmark("Bookmark 1");
 builder.startBookmark("Bookmark 2");
 builder.writeln(StringEscapeUtils.unescapeHtml("test title"));
 builder.endBookmark("Bookmark 1");
 builder.endBookmark("Bookmark 2");

Also, i have another doubt. Can i add bookmarks before and after the below line of code?

 builderClause.insertHtml(htmltext,true);

Thanks,

@pri_verd,

Thanks for your inquiry.

Yes, you can achieve your requirment using Aspose.Words and your code is correct.

Yes, you can add bookmark before and after this line of code.