GenerateDocument() public static method

public static GenerateDocument ( Document srcDoc, ArrayList nodes ) : Document
srcDoc Document
nodes System.Collections.ArrayList
return Document
        public static void Run()
        {
            // ExStart:ExtractContentBetweenParagraphStyles
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Gather a list of the paragraphs using the respective heading styles.
            ArrayList parasStyleHeading1 = Common.ParagraphsByStyleName(doc, "Heading 1");
            ArrayList parasStyleHeading3 = Common.ParagraphsByStyleName(doc, "Heading 3");

            // Use the first instance of the paragraphs with those styles.
            Node startPara1 = (Node)parasStyleHeading1[0];
            Node endPara1   = (Node)parasStyleHeading3[0];

            // Extract the content between these nodes in the document. Don't include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startPara1, endPara1, false);

            // Insert the content into a new separate document and save it to disk.
            Document dstDoc = Common.GenerateDocument(doc, extractedNodes);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            dstDoc.Save(dataDir);
            // ExEnd:ExtractContentBetweenParagraphStyles
            Console.WriteLine("\nExtracted content betweenn the paragraph styles successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            //ExStart:ExtractContentBetweenBookmark
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            Section section = doc.Sections[0];

            section.PageSetup.LeftMargin = 70.85;

            // Retrieve the bookmark from the document.
            Bookmark bookmark = doc.Range.Bookmarks["Bookmark1"];

            // We use the BookmarkStart and BookmarkEnd nodes as markers.
            BookmarkStart bookmarkStart = bookmark.BookmarkStart;
            BookmarkEnd   bookmarkEnd   = bookmark.BookmarkEnd;

            // Firstly extract the content between these nodes including the bookmark.
            ArrayList extractedNodesInclusive = Common.ExtractContent(bookmarkStart, bookmarkEnd, true);
            Document  dstDoc = Common.GenerateDocument(doc, extractedNodesInclusive);

            dstDoc.Save(dataDir + "TestFile.BookmarkInclusive_out_.doc");

            // Secondly extract the content between these nodes this time without including the bookmark.
            ArrayList extractedNodesExclusive = Common.ExtractContent(bookmarkStart, bookmarkEnd, false);

            dstDoc = Common.GenerateDocument(doc, extractedNodesExclusive);
            dstDoc.Save(dataDir + "TestFile.BookmarkExclusive_out_.doc");
            //ExEnd:ExtractContentBetweenBookmark
            Console.WriteLine("\nExtracted content between bookmarks successfully.\nFile saved at " + dataDir + "TestFile.BookmarkExclusive_out_.doc");
        }
Example #3
0
        public static void Run()
        {
            //ExStart:ExtractContentUsingField
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Use a document builder to retrieve the field start of a merge field.
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Pass the first boolean parameter to get the DocumentBuilder to move to the FieldStart of the field.
            // We could also get FieldStarts of a field using GetChildNode method as in the other examples.
            builder.MoveToMergeField("Fullname", false, false);

            // The builder cursor should be positioned at the start of the field.
            FieldStart startField = (FieldStart)builder.CurrentNode;
            Paragraph  endPara    = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 5, true);

            // Extract the content between these nodes in the document. Don't include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startField, endPara, false);

            // Insert the content into a new separate document and save it to disk.
            Document dstDoc = Common.GenerateDocument(doc, extractedNodes);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            dstDoc.Save(dataDir);
            //ExEnd:ExtractContentUsingField
            Console.WriteLine("\nExtracted content using the Field successfully.\nFile saved at " + dataDir);
        }
        public static void Run()
        {
            //ExStart:ExtractContentBetweenCommentRange
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithDocument();

            Document doc = new Document(dataDir + "TestFile.doc");

            // This is a quick way of getting both comment nodes.
            // Your code should have a proper method of retrieving each corresponding start and end node.
            CommentRangeStart commentStart = (CommentRangeStart)doc.GetChild(NodeType.CommentRangeStart, 0, true);
            CommentRangeEnd   commentEnd   = (CommentRangeEnd)doc.GetChild(NodeType.CommentRangeEnd, 0, true);

            // Firstly extract the content between these nodes including the comment as well.
            ArrayList extractedNodesInclusive = Common.ExtractContent(commentStart, commentEnd, true);
            Document  dstDoc = Common.GenerateDocument(doc, extractedNodesInclusive);

            dstDoc.Save(dataDir + "TestFile.CommentInclusive_out_.doc");

            // Secondly extract the content between these nodes without the comment.
            ArrayList extractedNodesExclusive = Common.ExtractContent(commentStart, commentEnd, false);

            dstDoc = Common.GenerateDocument(doc, extractedNodesExclusive);
            dstDoc.Save(dataDir + "TestFile.CommentExclusive_out_.doc");
            //ExEnd:ExtractContentBetweenCommentRange
            Console.WriteLine("\nExtracted content between the comment range successfully.\nFile saved at " + dataDir + "TestFile.CommentExclusive_out_.doc");
        }
Example #5
0
        public static void Run()
        {
            //ExStart:ExtractContentBetweenParagraphs
            // The path to the documents directory.
            string   dataDir  = RunExamples.GetDataDir_WorkingWithDocument();
            string   fileName = "TestFile.doc";
            Document doc      = new Document(dataDir + fileName);

            // Gather the nodes. The GetChild method uses 0-based index
            Paragraph startPara = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 6, true);
            Paragraph endPara   = (Paragraph)doc.FirstSection.GetChild(NodeType.Paragraph, 10, true);
            // Extract the content between these nodes in the document. Include these markers in the extraction.
            ArrayList extractedNodes = Common.ExtractContent(startPara, endPara, true);

            // Insert the content into a new separate document and save it to disk.
            Document dstDoc = Common.GenerateDocument(doc, extractedNodes);

            dataDir = dataDir + RunExamples.GetOutputFilePath(fileName);
            dstDoc.Save(dataDir);
            //ExEnd:ExtractContentBetweenParagraphs
            Console.WriteLine("\nExtracted content betweenn the paragraphs successfully.\nFile saved at " + dataDir);
        }