Hi Yuri,
Thanks for your inquiry.
Please see the code below which demonstrates how to append the content of documents at the paragraph level.
public static void AppendDocumentAtParagraphLevel(Document dstDoc, Document srcDoc)
{
Paragraph lastPara = dstDoc.FirstSection.Body.LastParagraph;
foreach (Section section in srcDoc.Sections)
{
foreach (Node blockNode in section.Body)
{
CompositeNode newNode = (CompositeNode)lastPara.Document.ImportNode(blockNode, true, ImportFormatMode.KeepSourceFormatting);
Node insertNode = lastPara.LastChild;
if (newNode.NodeType == NodeType.Paragraph || newNode.NodeType == NodeType.StructuredDocumentTag || newNode.NodeType == NodeType.CustomXmlMarkup)
{
// Use GetChildNodes to find runs that are deeply nested even if the paragraph is wrapped within a SDT or CustomXml markup
foreach (Node inlineNode in newNode.GetChildNodes(NodeType.Run, true))
{
lastPara.InsertAfter(inlineNode, insertNode);
insertNode = inlineNode;
}
}
else if (newNode.NodeType == NodeType.Table)
{
lastPara.ParentNode.InsertAfter(newNode, lastPara);
}
}
}
}
If you have any further queries, please feel free to ask.
Thanks,
Adam Skelton
Programming Writer
Aspose Auckland Team