I am using CompositeNode,InsertAfter to insert a text in a bookmark. But using this function, an empty line is inserted before my text and the beginning of the bookmark. What am I doing wrong? I want the text to be inserted right at the beginning of the bookmark
Here a solution with the code:
TestInsertRTF.zip (5.3 MB)
Another simple way that you can use to get the desired output is as follows:
Document doc = new Document("D:\\TestInsertRTF\\Template.docx");
Document importDoc = new Document("D:\\TestInsertRTF\\Context.RTF");
Bookmark currentBookmark = doc.Range.Bookmarks["ADDITIONAL_TEXT"];
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark(currentBookmark.Name, true, true);
builder.InsertDocument(importDoc, ImportFormatMode.KeepSourceFormatting);
Paragraph emptyPara = (Paragraph) currentBookmark.BookmarkEnd.ParentNode;
Paragraph prevPara = (Paragraph)emptyPara.PreviousSibling;
prevPara.AppendChild(currentBookmark.BookmarkEnd);
emptyPara.Remove();
doc.Save("D:\\TestInsertRTF\\18.11.docx");