Hi,
I am trying to merge 2 documents. First is the original document and second is the processed document. The second processed document content is wrapped in a bookmark.
@KCSR I am afraid, it is not possible to wrap content of the inserted document into a paragraph. Paragraphs can contain only inline nodes as children - Run, Shape etc. Please see our documentation to learn more about Document Object Model.
Also, you can use DocumentExplorer demo application to investigate your documents’ internal representation.
Yes I also thought the same. Thanks for confirming Alexey.
Is it possible to put first document content in one section and processed document content in another section? Like shown below - step 1 to 3 in one section and step 4-6 in another. I am looking for this option is because when I convert the final word document to ooxml and send to front end. The front-end developers have js code to alter the final word document and when they try to remove the other (not the one I have inserted) bookmarks in document then my bookmark start range is getting automatically shifted to first document start index.
@KCSR Since you are adding source ProcessedDocument at the end of your target document, I would suggest you to use Document.AppendDocument method instead of DocumentBuilder.InsertDocument. In this case section of the appended document will be retained. For example you can use the following code to wrap whole content of the source document into a bookmark and then append it to the target document:
Document target = new Document(@"C:\Temp\target.docx");
Document src = new Document(@"C:\Temp\src.docx");
// Wrap source document into a bookmark.
string bkName = "my_cool_bookmakr";
src.FirstSection.Body.PrependChild(new BookmarkStart(src, bkName));
src.LastSection.Body.AppendChild(new BookmarkEnd(src, bkName));
// Append source document to the target document.
target.AppendDocument(src, ImportFormatMode.KeepSourceFormatting);
target.Save(@"C:\Temp\out.docx");