Insert new Book Marks to an existing Word by Aspose Word

Dear Aspose Team:

Now, I am trying to implement a function that insert new Book Mark to an existing Word.
For example, some text in the existing Word document as follows:

The company’s consultancy service unit reported EBITDA* of $.8 million,
a 5.5% improvement, even though contracts decreased compared to the same
quarter last year. Adventure Works continues to improve its
services, said Annik Stahl, Chair of the Board and Chief Executive
Officer of Adventure Works

The Word document have no any Book Mark at first. And I want to create an new Book Mark that include the text “Adventure Works continues to improve its services” by the DocumentBuilder.

Whether the Aspose component can support me to add the new book mark include the text I expected just like in the Microsoft Word.

Thanks
Jason

Hi Jason,

Thanks for your inquiry. Please use the following code snippet to inset bookmark in an existing document. Following code snippet insert the bookmark after third Paragraph. The contents of forth Paragprah will be inside bookamrk ‘newBookmark’. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "in.docx");
DocumentBuilder builder = new DocumentBuilder(doc);
Node start = doc.getChild(NodeType.PARAGRAPH, 2, true);
Node end = doc.getChild(NodeType.PARAGRAPH, 3, true);
builder.moveTo(start);
builder.startBookmark("newBookmark");
builder.moveTo(end);
builder.endBookmark("newBookmark");
doc.save(MyDir + "out.docx");