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

Free Support Forum - aspose.com

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:
<span lang=“EN-US” style=“font-size:10.5pt;mso-bidi-font-size:
11.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA”>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
<span lang=“EN-US” style=“font-size:10.5pt;mso-bidi-font-size:
11.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA”>…
<span lang=“EN-US” style=“font-size:10.5pt;mso-bidi-font-size:
11.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA”>
<span lang=“EN-US” style=“font-size:10.5pt;mso-bidi-font-size:
11.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA”>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





<span lang=“EN-US” style=“font-size:10.5pt;mso-bidi-font-size:
11.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA”>
<span lang=“EN-US” style=“font-size:10.5pt;mso-bidi-font-size:
11.0pt;font-family:“Arial”,“sans-serif”;mso-fareast-font-family:宋体;mso-fareast-theme-font:
minor-fareast;mso-ansi-language:EN-US;mso-fareast-language:ZH-CN;mso-bidi-language:
AR-SA”>

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”);<o:p></o:p>

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");