Insert Document into another Document

Last post 07-30-2010, 6:24 AM by AndreyN. 9 replies.
Sort Posts: Previous Next
  •  06-23-2010, 3:49 AM 244948

    Insert Document into another Document

    Hello,

    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!

     
  •  06-23-2010, 4:09 AM 244953 in reply to 244948

    Re: Insert Document into another Document

    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.

    Thanks,


    Adam Skelton
    Programming Writer
    Aspose Auckland Team
     
  •  07-15-2010, 2:30 AM 248791 in reply to 244953

    Re: Insert Document into another Document

    Hello,

    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!

    Candy

     
  •  07-15-2010, 8:01 AM 248845 in reply to 248791

    Re: Insert Document into another Document

    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:

    http://www.aspose.com/documentation/.net-components/aspose.words-for-.net/aspose.words.documentbuilder.inserttableofcontents.html

     

    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");

    doc.UpdateFields();

    doc.UpdatePageLayout();

    doc.Save("out.doc");

     

    Best regards,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  07-15-2010, 9:00 PM 248940 in reply to 248845

    Re: Insert Document into another Document

    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 .
     
  •  07-16-2010, 7:09 AM 249025 in reply to 248940

    Re: Insert Document into another Document

    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,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  07-29-2010, 8:29 PM 251202 in reply to 249025

    Re: Insert Document into another Document

    Attachment: Present (inaccessible)
    Hello,
    Thanks for your reply.
    The attachment is my your input and expected output document.
    Best Regards,
    Candy
     
  •  07-30-2010, 2:55 AM 251259 in reply to 251202

    Re: Insert Document into another Document

    Attachment: Present (inaccessible)

    Hello

     

    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())

                        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,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
  •  07-30-2010, 4:58 AM 251279 in reply to 251259

    Re: Insert Document into another Document

    Attachment: Present (inaccessible)

    Hello,

    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 ?

     
  •  07-30-2010, 6:24 AM 251290 in reply to 251279

    Re: Insert Document into another Document

    Hello

     

    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

    http://www.aspose.com/corporate/purchase/faqs/temporary-license.aspx

     

    Best regards,


    Andrey Noskov
    Developer/Technical Support
    Aspose Auckland Team
     
View as RSS news feed in XML