Creating bookmark using DocumentBuilder to include whole paragraph inside (including paragraph end mark)

OutputFiles.zip (26.1 KB)

Hi,

we need to be able to create a bookmark using DocumentBuilder class (so documentBuilder.StartBookmark(_bookmarkName) / documentBuilder.EndBookmark(_bookmarkName)) so it includes whole last paragrph of the document (example expected output and incorrect output included). Basically the idea is for the bookmark to have body of the document as parent node instead of Paragraph.

could you please let us know how this could be done?

Thanks
aga

@acturisaspose

Thanks for your inquiry. In your case, you need to use the CompositeNode.InsertBefore or CompositeNode.InsertAfter methods to insert the BookmarkStart and BookmarkEnd nodes at block level. Hope this helps you.

Document doc = new Document(MyDir + "in.docx");
// Your code....
// Your code....
// Your code....

doc.LastSection.Body.InsertAfter(new BookmarkEnd(doc, "bookmark"), doc.LastSection.Body.LastParagraph);

doc.Save(MyDir + "18.11.docx");