facebooktwittermenuarrow-up

GemBox Support Forum

Creating a bookmark on a word

How to add a bookmark to a specific location in a document.
For example, we look for and find a word in the document and we want to bookmark that word.
Thank you in advance!

Hi Patrick,

Try this:

DocumentModel document = DocumentModel.Load("input.docx");

string searchWord = "MyWord";
string bookmarkName = "MyBookmark";

ContentRange content = document.Content.Find(searchWord).First();
content.End.InsertRange(new BookmarkEnd(document, bookmarkName).Content);
content.Start.InsertRange(new BookmarkStart(document, bookmarkName).Content);

document.Save("output.docx");

I hope it helps.

Regards,
Mario