We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Insert Document into another Document

I know Aspose.Words for Java can implement iserting document into another document.Can you give me a simple example for this? Thank you very much!

Hi Candy,
You can find the documentation on how to insert a document into another document along with code examples here.
Please feel free to ask if you have any further queries.

There’s other problem troubled me.
After I inserted a document into another document ,how can I build the catalog of the docment.
The bulletedlist and the number can updated automatically after the template merging ?
Thank you!

Hello Candy,

Thanks for your request. I suppose when you say “catalog” you mean TOC (Table of Content). Please see the following link to learn how to insert TOC in the document:
Then when you call the Document.UpdateFields method, Aspose.Words updates (entirely rebuilds) the TOC field, but does not insert page numbers into the TOC field yet. Aspose.Words calculates correct page numbers and inserts into the TOC when the document layout is built e.g. when you save to PDF or print. So to update page numbers in TOC, you should call Document.UpdatePageLayout or just save document in PDF or XPS.

Document doc = new Document("TestTOC.doc");

Best regards,

Thanks for your reply.
I want know that the Bullet can updated automatically after the template merging.
The bullet is like this:
Create .
Navigate .
Insert .

Hello Candy,

Thanks for your request. Could you please be more specific regarding the problem with bullets, it is not quite clear for me how a bulleted list should be updated after merging. Please attach your input and expected output document? I will check the problem and provide you more information.
Best regards,

Thanks for your reply.
The attachment is my your input and expected output document.
Best Regards,


Thanks for your request. You should just update styles of your lists (please see the attached screenshot). I little bit changed your documents for you and attached final document produced using the following code:

Document doc1 = new Document("C:\\Temp\\input1.doc");
Document doc2 = new Document("C:\\Temp\\input2.doc");
insertDocument(doc1.getFirstSection().getBody().getLastParagraph(), doc2);
doc1.save("C:\\Temp\\out.doc", SaveFormat.DOC);
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.USE_DESTINATION_STYLES);
    // Loop through all sections in the source document.
    for (Section srcSection : srcDoc.getSections())
        // Loop through all block level nodes (paragraphs and tables) in the body of the section.
        for (Node srcNode : srcSection.getBody())
            // 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())
            // 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,

Thanks for your reply.
I try your method,but it doesn’t update automatically.The attachment is the file I output.Is there something I missed to do ?


Thank you for additional information. I have tested one more time, all works fine. Please try using the attached documents and the code and of course the latest version of Aspose.Words for NET (9.2.0) or Java (4.0.2). Also if you would like to test Aspose products without the evaluation version limitations, you can request a 30-day Temporary License. Please refer to
Best regards,