Beispiel #1
0
        private static void InsertSlicedSectionIntoOutput(Document asposeDoc, int start, int currentIndex, Document outputDoc, Queue <int> mainSections)
        {
            var slicedSection = GetSliceOfSection((Section)asposeDoc.FirstSection.Clone(true), start, currentIndex);

            if (IsNullOrWhiteSpaceOrLineBreak(slicedSection.Body.GetText()))
            {
                return;                                                              // don't add empty sections
            }
            slicedSection.HeadersFooters.LinkToPrevious(false);
            var slicedSectionToInsert = outputDoc.ImportNode(slicedSection, true, ImportFormatMode.KeepSourceFormatting);

            outputDoc.AppendChild(slicedSectionToInsert);
        }
Beispiel #2
0
        private static void InsertAttachmentDocIntoOutput(byte[] attachment, Document outputDoc, double w, double h)
        {
            using (var mergedStream = new MemoryStream(attachment))
            {
                var attachmentDocument = new Document(mergedStream);

                attachmentDocument.FirstSection.HeadersFooters.LinkToPrevious(false);
                attachmentDocument.FirstSection.PageSetup.PageWidth  = w;
                attachmentDocument.FirstSection.PageSetup.PageHeight = h;
                var sectionFromAttachment = outputDoc.ImportNode(attachmentDocument.FirstSection, true, ImportFormatMode.KeepSourceFormatting);

                outputDoc.AppendChild(sectionFromAttachment);
            }
        }
        public void ImportNode()
        {
            //ExStart
            //ExFor:DocumentBase.ImportNode(Node, Boolean)
            //ExSummary:Shows how to import a node from one document to another.
            Document srcDoc = new Document();
            Document dstDoc = new Document();

            srcDoc.FirstSection.Body.FirstParagraph.AppendChild(
                new Run(srcDoc, "Source document first paragraph text."));
            dstDoc.FirstSection.Body.FirstParagraph.AppendChild(
                new Run(dstDoc, "Destination document first paragraph text."));

            // Every node has a parent document, which is the document that contains the node.
            // Inserting a node into a document that the node does not belong to will throw an exception.
            Assert.AreNotEqual(dstDoc, srcDoc.FirstSection.Document);
            Assert.Throws <ArgumentException>(() => { dstDoc.AppendChild(srcDoc.FirstSection); });

            // Use the ImportNode method to create a copy of a node, which will have the document
            // that called the ImportNode method set as its new owner document.
            Section importedSection = (Section)dstDoc.ImportNode(srcDoc.FirstSection, true);

            Assert.AreEqual(dstDoc, importedSection.Document);

            // We can now insert the node into the document.
            dstDoc.AppendChild(importedSection);

            Assert.AreEqual("Destination document first paragraph text.\r\nSource document first paragraph text.\r\n",
                            dstDoc.ToString(SaveFormat.Text));
            //ExEnd

            Assert.AreNotEqual(importedSection, srcDoc.FirstSection);
            Assert.AreNotEqual(importedSection.Document, srcDoc.FirstSection.Document);
            Assert.AreEqual(importedSection.Body.FirstParagraph.GetText(),
                            srcDoc.FirstSection.Body.FirstParagraph.GetText());
        }
Beispiel #4
0
        private Aspose.Pdf.Document doc_to_pdf(save_progress progress, System.Windows.Forms.Form dlg, int lst_select)
        {
            int num = 50;

            if (lst_select == 7)
            {
                num = 100;
            }
            Aspose.Pdf.Document document2 = new Aspose.Pdf.Document();
            try
            {
                document2.Pages.Delete();
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { 0 });
                }
                if (this.word_doc == null)
                {
                    return(null);
                }
                for (int i = 0; i < this.word_doc.ChildNodes.Count; i++)
                {
                    MemoryStream          stream   = new MemoryStream();
                    Aspose.Words.Document document = new Aspose.Words.Document();
                    document.ChildNodes.RemoveAt(0);
                    document.AppendChild(document.ImportNode(this.word_doc.ChildNodes[i], true));
                    document.Save(stream, Aspose.Words.SaveFormat.Pdf);
                    document2.Pages.Add(new Aspose.Pdf.Document(stream).Pages);
                    if (progress != null)
                    {
                        dlg.Invoke(progress, new object[] { (i * num) / this.word_doc.ChildNodes.Count });
                    }
                }
                if (lst_select == 7)
                {
                    document2.Save(this.global_config.target_dic + Path.GetFileNameWithoutExtension(this.file_path) + this.get_suffix());
                }
                if (progress != null)
                {
                    dlg.Invoke(progress, new object[] { num });
                }
            }
            catch (Exception)
            {
                return(null);
            }
            return(document2);
        }
Beispiel #5
0
        public void CreateFromScratch()
        {
            //ExStart
            //ExFor:Node.GetText
            //ExFor:CompositeNode.RemoveAllChildren
            //ExFor:CompositeNode.AppendChild
            //ExFor:Section
            //ExFor:Section.#ctor
            //ExFor:Section.PageSetup
            //ExFor:PageSetup.SectionStart
            //ExFor:PageSetup.PaperSize
            //ExFor:SectionStart
            //ExFor:PaperSize
            //ExFor:Body
            //ExFor:Body.#ctor
            //ExFor:Paragraph
            //ExFor:Paragraph.#ctor
            //ExFor:Paragraph.ParagraphFormat
            //ExFor:ParagraphFormat
            //ExFor:ParagraphFormat.StyleName
            //ExFor:ParagraphFormat.Alignment
            //ExFor:ParagraphAlignment
            //ExFor:Run
            //ExFor:Run.#ctor(DocumentBase)
            //ExFor:Run.Text
            //ExFor:Inline.Font
            //ExSummary:Creates a simple document from scratch using the Aspose.Words object model.

            // Create an "empty" document. Note that like in Microsoft Word,
            // the empty document has one section, body and one paragraph in it.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // This truly makes the document empty. No sections (not possible in Microsoft Word).
            doc.RemoveAllChildren();

            // Create a new section node.
            // Note that the section has not yet been added to the document,
            // but we have to specify the parent document.
            Aspose.Words.Section section = new Aspose.Words.Section(doc);

            // Append the section to the document.
            doc.AppendChild(section);

            // Lets set some properties for the section.
            section.PageSetup.SectionStart = SectionStart.NewPage;
            section.PageSetup.PaperSize    = PaperSize.Letter;


            // The section that we created is empty, lets populate it. The section needs at least the Body node.
            Body body = new Body(doc);

            section.AppendChild(body);


            // The body needs to have at least one paragraph.
            // Note that the paragraph has not yet been added to the document,
            // but we have to specify the parent document.
            // The parent document is needed so the paragraph can correctly work
            // with styles and other document-wide information.
            Paragraph para = new Paragraph(doc);

            body.AppendChild(para);

            // We can set some formatting for the paragraph
            para.ParagraphFormat.StyleName = "Heading 1";
            para.ParagraphFormat.Alignment = ParagraphAlignment.Center;


            // So far we have one empty paragraph in the document.
            // The document is valid and can be saved, but lets add some text before saving.
            // Create a new run of text and add it to our paragraph.
            Run run = new Run(doc);

            run.Text       = "Hello World!";
            run.Font.Color = System.Drawing.Color.Red;
            para.AppendChild(run);


            // As a matter of interest, you can retrieve text of the whole document and
            // see that \x000c is automatically appended. \x000c is the end of section character.
            Console.WriteLine("Hello World!\x000c", doc.GetText());

            // Save the document.
            doc.Save(MyDir + "Section.CreateFromScratch Out.doc");
            //ExEnd

            Assert.AreEqual("Hello World!\x000c", doc.GetText());
        }
Beispiel #6
-1
        public void CreateFromScratch()
        {
            //ExStart
            //ExFor:Node.GetText
            //ExFor:CompositeNode.RemoveAllChildren
            //ExFor:CompositeNode.AppendChild
            //ExFor:Section
            //ExFor:Section.#ctor
            //ExFor:Section.PageSetup
            //ExFor:PageSetup.SectionStart
            //ExFor:PageSetup.PaperSize
            //ExFor:SectionStart
            //ExFor:PaperSize
            //ExFor:Body
            //ExFor:Body.#ctor
            //ExFor:Paragraph
            //ExFor:Paragraph.#ctor
            //ExFor:Paragraph.ParagraphFormat
            //ExFor:ParagraphFormat
            //ExFor:ParagraphFormat.StyleName
            //ExFor:ParagraphFormat.Alignment
            //ExFor:ParagraphAlignment
            //ExFor:Run
            //ExFor:Run.#ctor(DocumentBase)
            //ExFor:Run.Text
            //ExFor:Inline.Font
            //ExSummary:Creates a simple document from scratch using the Aspose.Words object model.

            // Create an "empty" document. Note that like in Microsoft Word,
            // the empty document has one section, body and one paragraph in it.
            Aspose.Words.Document doc = new Aspose.Words.Document();

            // This truly makes the document empty. No sections (not possible in Microsoft Word).
            doc.RemoveAllChildren();

            // Create a new section node.
            // Note that the section has not yet been added to the document,
            // but we have to specify the parent document.
            Aspose.Words.Section section = new Aspose.Words.Section(doc);

            // Append the section to the document.
            doc.AppendChild(section);

            // Lets set some properties for the section.
            section.PageSetup.SectionStart = SectionStart.NewPage;
            section.PageSetup.PaperSize = PaperSize.Letter;

            // The section that we created is empty, lets populate it. The section needs at least the Body node.
            Body body = new Body(doc);
            section.AppendChild(body);

            // The body needs to have at least one paragraph.
            // Note that the paragraph has not yet been added to the document,
            // but we have to specify the parent document.
            // The parent document is needed so the paragraph can correctly work
            // with styles and other document-wide information.
            Paragraph para = new Paragraph(doc);
            body.AppendChild(para);

            // We can set some formatting for the paragraph
            para.ParagraphFormat.StyleName = "Heading 1";
            para.ParagraphFormat.Alignment = ParagraphAlignment.Center;

            // So far we have one empty paragraph in the document.
            // The document is valid and can be saved, but lets add some text before saving.
            // Create a new run of text and add it to our paragraph.
            Run run = new Run(doc);
            run.Text = "Hello World!";
            run.Font.Color = System.Drawing.Color.Red;
            para.AppendChild(run);

            // As a matter of interest, you can retrieve text of the whole document and
            // see that \x000c is automatically appended. \x000c is the end of section character.
            Console.WriteLine("Hello World!\x000c", doc.GetText());

            // Save the document.
            doc.Save(ExDir + "Section.CreateFromScratch Out.doc");
            //ExEnd

            Assert.AreEqual("Hello World!\x000c", doc.GetText());
        }