Free Support Forum - aspose.com

Bookmark End points to another paragraph

Hello Support


I have attached sample document with 2 bookmarks “bm1” and “bm2”. First bookmark includes special paragraph character and second doesn’t.

And there is an issue when I try to paste paragraphs after first bookmark. Content is not pasted directly after bookmark but after next paragraph. But all fine if I try to do the same with second bookmark.

On the screenshots it’s shown that BookmarkEnd is placed on the next paragraph. Is it correct?
Or can you please explain how to exclude last paragraph character from bookmark programmatically?

Regards
Kirill
Hi Kirill,

Thanks for your inquiry. We suggest you please read about Aspose.Words' DOM from here:
Aspose.Words Document Object Model

You are facing the expected behavior of Aspose.Words. The BookmarkEnd node of "bm1" is after the paragraph break mark (at the start of paragraph 3). Please check the attached DOM image for detail.

Please use following code example to get the desired output. Following code example inserts the BookmarkEnd node at the end of paragraph 2.

Document doc = new Document(MyDir + "Paragraph-in-bookmark.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

Bookmark bm = doc.Range.Bookmarks["bm1"];

Paragraph paragraph = (Paragraph)bm.BookmarkStart.ParentNode;

paragraph.AppendChild(new BookmarkEnd(doc, "bm1"));

doc.Save(MyDir + "Out v17.1.0.docx");