Hi
Thanks for your inquiry. Here is changed insertDocuemnt method.
/// <summary>
/// Inserts content of the external document after the specified node.
/// Section breaks and section formatting of the inserted document are ignored.
/// </summary>
/// <param name="insertAfterNode">Node in the destination document after which the content
/// should be inserted. This node should be a block level node (paragraph or table).</param>
/// <param name="srcDoc">The document to insert.</param>
private static void InsertDocument1(Node insertAfterNode, Document srcDoc) throws Exception
{
// Make sure that the node is either a pargraph or table.
if ((insertAfterNode.getNodeType() != NodeType.PARAGRAPH) &
(insertAfterNode.getNodeType() != NodeType.TABLE))
throw new Exception("The destination node should be either a paragraph or table.");
// We will be inserting into the parent of the destination paragraph.
CompositeNode dstStory = insertAfterNode.getParentNode();
// This object will be translating styles and lists during the import.
NodeImporter importer = new NodeImporter(srcDoc, insertAfterNode.getDocument(), ImportFormatMode.KEEP_SOURCE_FORMATTING);
// Loop through all sections in the source document.
for (int sectIdx = 0; sectIdx < srcDoc.getSections().getCount(); sectIdx++)
{
Section srcSection = srcDoc.getSections().get(sectIdx);
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
for (int nodeIdx = 0; nodeIdx < srcSection.getBody().getChildNodes().getCount(); nodeIdx++)
{
Node srcNode = srcSection.getBody().getChildNodes().get(nodeIdx);
// Let's skip the node if it is a last empty paragarph in a section.
if (srcNode.getNodeType() == NodeType.PARAGRAPH)
{
Paragraph para = (Paragraph)srcNode;
if (para.isEndOfSection() && !para.hasChildNodes())
continue;
}
// This creates a clone of the node, suitable for insertion into the destination document.
Node newNode = importer.importNode(srcNode, true);
// Insert new node after the reference node.
dstStory.insertAfter(newNode, insertAfterNode);
insertAfterNode = newNode;
}
}
}
Hope this helps.
Best regards.
Alexey Noskov
Developer/Technical Support
Aspose Auckland Team