Hi we are currently inserting a new document into the main document after the last line of the specified paragraph. So the new document is placed as a new paragraph.
We are trying to place the new document at the end of the specified paragraph, instead of the placing the new document a line after the end of paragraph. Can you suggest if there is a solution for this?
Following code is used for inserting word document which is provided by aspose team
private static void insertDocument(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);
SectionCollection sectionColl = srcDoc.getSections();
// Loop through all sections in the source document.
for (int sec = 0; sec <sectionColl.getCount(); sec++)
{
Section srcSection = (Section) sectionColl.get(sec);
Body body = srcSection.getBody();
NodeCollection nodeColl = body.getChildNodes();
// Loop through all block level nodes (paragraphs and tables) in the body of the section.
for (int nodeCount = 0; nodeCount <nodeColl.getCount(); nodeCount++)
{
Node srcNode = (Node) nodeColl.get(nodeCount);
// 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;
}
}
}