public static void Run()
        {
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_JoiningAndAppending();

            Document         dstDoc = new Document(dataDir + "TestFile.Destination.doc");
            Document         srcDoc = new Document(dataDir + "TestFile.Source.doc");
            ImportFormatMode mode   = ImportFormatMode.KeepSourceFormatting;

            // Loop through all sections in the source document.
            // Section nodes are immediate children of the Document node so we can just enumerate the Document.
            foreach (Section srcSection in srcDoc)
            {
                // Because we are copying a section from one document to another,
                // it is required to import the Section node into the destination document.
                // This adjusts any document-specific references to styles, lists, etc.
                //
                // Importing a node creates a copy of the original node, but the copy
                // is ready to be inserted into the destination document.
                Node dstSection = dstDoc.ImportNode(srcSection, true, mode);

                // Now the new section node can be appended to the destination document.
                dstDoc.AppendChild(dstSection);
            }

            // Save the joined document
            dstDoc.Save(dataDir + "TestFile.Append Manual Out.doc");

            Console.WriteLine("\nDocument appended successfully with manual append operation.\nFile saved at " + dataDir + "TestFile.Append Manual Out.pdf");
        }
Example #2
0
        private static void AppendDocument(Document dstDoc, Document srcDoc, ImportFormatMode mode)
        {
            // Loop through all sections in the source document.
            // Section nodes are immediate children of the Document node so we can just enumerate the Document.
            foreach (Section srcSection in srcDoc)
            {
                // Because we are copying a section from one document to another,
                // it is required to import the Section node into the destination document.
                // This adjusts any document-specific references to styles, lists, etc.
                //
                // Importing a node creates a copy of the original node, but the copy
                // is ready to be inserted into the destination document.
                Node dstSection = dstDoc.ImportNode(srcSection, true, mode);

                // Now the new section node can be appended to the destination document.
                dstDoc.AppendChild(dstSection);
            }
        }
        public static void DoPrepend(Document dstDoc, Document srcDoc, ImportFormatMode mode)
        {
            // Loop through all sections in the source document.
            // Section nodes are immediate children of the Document node so we can just enumerate the Document.
            ArrayList sections = new ArrayList(srcDoc.Sections.ToArray());

            // Reverse the order of the sections so they are prepended to start of the destination document in the correct order.
            sections.Reverse();

            foreach (Section srcSection in sections)
            {
                // Import the nodes from the source document.
                Node dstSection = dstDoc.ImportNode(srcSection, true, mode);

                // Now the new section node can be prepended to the destination document.
                // Note how PrependChild is used instead of AppendChild. This is the only line changed compared
                // To the original method.
                dstDoc.PrependChild(dstSection);
            }
        }
        public static void DoPrepend(Document dstDoc, Document srcDoc, ImportFormatMode mode)
        {
            // Loop through all sections in the source document.
            // Section nodes are immediate children of the Document node so we can just enumerate the Document.
            ArrayList sections = new ArrayList(srcDoc.Sections.ToArray());

            // Reverse the order of the sections so they are prepended to start of the destination document in the correct order.
            sections.Reverse();

            foreach (Section srcSection in sections)
            {
                // Import the nodes from the source document.
                Node dstSection = dstDoc.ImportNode(srcSection, true, mode);

                // Now the new section node can be prepended to the destination document.
                // Note how PrependChild is used instead of AppendChild. This is the only line changed compared
                // to the original method.
                dstDoc.PrependChild(dstSection);
            }
        }
        //ExEnd
        //ExStart
        //ExFor:DocumentBase.ImportNode(Node,bool,ImportFormatMode)
        //ExFor:ImportFormatMode
        //ExId:CombineDocuments
        //ExSummary:Shows how to manually append the content from one document to the end of another document.
        /// <summary>
        /// A manual implementation of the Document.AppendDocument function which shows the general 
        /// steps of how a document is appended to another.
        /// </summary>
        /// <param name="dstDoc">The destination document where to append to.</param>
        /// <param name="srcDoc">The source document.</param>
        /// <param name="mode">The import mode to use when importing content from another document.</param>
        public void AppendDocument(Document dstDoc, Document srcDoc, ImportFormatMode mode)
        {
            // Loop through all sections in the source document.
            // Section nodes are immediate children of the Document node so we can just enumerate the Document.
            foreach (Section srcSection in srcDoc)
            {
                // Because we are copying a section from one document to another,
                // it is required to import the Section node into the destination document.
                // This adjusts any document-specific references to styles, lists, etc.
                //
                // Importing a node creates a copy of the original node, but the copy
                // is ready to be inserted into the destination document.
                Node dstSection = dstDoc.ImportNode(srcSection, true, mode);

                // Now the new section node can be appended to the destination document.
                dstDoc.AppendChild(dstSection);
            }
        }