当前位置: 首页>>代码示例>>C#>>正文


C# DocumentBuilder类代码示例

本文整理汇总了C#中DocumentBuilder的典型用法代码示例。如果您正苦于以下问题:C# DocumentBuilder类的具体用法?C# DocumentBuilder怎么用?C# DocumentBuilder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


DocumentBuilder类属于命名空间,在下文中一共展示了DocumentBuilder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: VerticalMerge

        // ExEnd:PrintCellMergeType
        public static void VerticalMerge( string dataDir)
        {
            // ExStart:VerticalMerge           
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            builder.InsertCell();
            builder.CellFormat.VerticalMerge = CellMerge.First;
            builder.Write("Text in merged cells.");

            builder.InsertCell();
            builder.CellFormat.VerticalMerge = CellMerge.None;
            builder.Write("Text in one cell");
            builder.EndRow();

            builder.InsertCell();
            // This cell is vertically merged to the cell above and should be empty.
            builder.CellFormat.VerticalMerge = CellMerge.Previous;

            builder.InsertCell();
            builder.CellFormat.VerticalMerge = CellMerge.None;
            builder.Write("Text in another cell");
            builder.EndRow();
            builder.EndTable();
            dataDir = dataDir + "Table.VerticalMerge_out.doc";

            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:VerticalMerge
            Console.WriteLine("\nTable created successfully with two columns with cells merged vertically in the first column.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:32,代码来源:MergedCells.cs

示例2: AutoFitToPageWidth

        /// <summary>
        /// Shows how to set a table to auto fit to 50% of the page width.
        /// </summary>
        private static void AutoFitToPageWidth(string dataDir)
        {
            // ExStart:AutoFitToPageWidth
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a table with a width that takes up half the page width.
            Table table = builder.StartTable();

            // Insert a few cells
            builder.InsertCell();
            table.PreferredWidth = PreferredWidth.FromPercent(50);
            builder.Writeln("Cell #1");

            builder.InsertCell();
            builder.Writeln("Cell #2");

            builder.InsertCell();
            builder.Writeln("Cell #3");

            dataDir = dataDir + "Table.PreferredWidth_out.doc";
           
            // Save the document to disk.
            doc.Save(dataDir);
            // ExEnd:AutoFitToPageWidth
            Console.WriteLine("\nTable autofit successfully to 50% of the page width.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:30,代码来源:SpecifyHeightAndWidth.cs

示例3: AddImageToPage

        /// <summary>
        /// Adds an image to a page using the supplied paragraph.
        /// </summary>
        /// <param name="para">The paragraph to an an image to.</param>
        /// <param name="page">The page number the paragraph appears on.</param>
        public static void AddImageToPage(Paragraph para, int page)
        {
            Document doc = (Document)para.Document;

            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.MoveTo(para);

            // Add a logo to the top left of the page. The image is placed infront of all other text.
            Shape shape = builder.InsertImage(gDataDir + "Aspose Logo.png", RelativeHorizontalPosition.Page, 60,
                RelativeVerticalPosition.Page, 60, -1, -1, WrapType.None);

            // Add a textbox next to the image which contains some text consisting of the page number.
            Shape textBox = new Shape(doc, ShapeType.TextBox);

            // We want a floating shape relative to the page.
            textBox.WrapType = WrapType.None;
            textBox.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
            textBox.RelativeVerticalPosition = RelativeVerticalPosition.Page;

            // Set the textbox position.
            textBox.Height = 30;
            textBox.Width = 200;
            textBox.Left = 150;
            textBox.Top = 80;

            // Add the textbox and set text.
            textBox.AppendChild(new Paragraph(doc));
            builder.InsertNode(textBox);
            builder.MoveTo(textBox.FirstChild);
            builder.Writeln("This is a custom note for page " + page);
        }
开发者ID:nancyeiceblue,项目名称:Aspose_Words_NET,代码行数:36,代码来源:Program.cs

示例4: DocumentBuilder

            /// <summary>
            /// Called for every merge field encountered in the document.
            /// We can either return some data to the mail merge engine or do something
            /// Else with the document. In this case we modify cell formatting.
            /// </summary>
            void IFieldMergingCallback.FieldMerging(FieldMergingArgs e)
            {
                if (mBuilder == null)
                    mBuilder = new DocumentBuilder(e.Document);

                // This way we catch the beginning of a new row.
                if (e.FieldName.Equals("CompanyName"))
                {
                    // Select the color depending on whether the row number is even or odd.
                    Color rowColor;
                    if (IsOdd(mRowIdx))
                        rowColor = Color.FromArgb(213, 227, 235);
                    else
                        rowColor = Color.FromArgb(242, 242, 242);

                    // There is no way to set cell properties for the whole row at the moment,
                    // So we have to iterate over all cells in the row.
                    for (int colIdx = 0; colIdx < 4; colIdx++)
                    {
                        mBuilder.MoveToCell(0, mRowIdx, colIdx, 0);
                        mBuilder.CellFormat.Shading.BackgroundPatternColor = rowColor;
                    }

                    mRowIdx++;
                }
            }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:31,代码来源:MailMergeAlternatingRows.cs

示例5: StudentBasicInfo

        public StudentBasicInfo(DocumentBuilder builder)
        {
            InitializeField();

            _builder = builder;
            _builder.Document.MailMerge.MergeField += new Aspose.Words.Reporting.MergeFieldEventHandler(MailMerge_MergeField);
        }
开发者ID:ChunTaiChen,项目名称:KaoHsiung.StudentRecordReport,代码行数:7,代码来源:StudentBasicInfo.cs

示例6: Run

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

            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a few page breaks (just for testing)
            for (int i = 0; i < 5; i++)
                builder.InsertBreak(BreakType.PageBreak);

            // Move the DocumentBuilder cursor into the primary footer.
            builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

            // We want to insert a field like this:
            // { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" }
            Field field = builder.InsertField(@"IF ");
            builder.MoveTo(field.Separator);
            builder.InsertField("PAGE");
            builder.Write(" <> ");
            builder.InsertField("NUMPAGES");
            builder.Write(" \"See Next Page\" \"Last Page\" ");

            // Finally update the outer field to recalcaluate the final value. Doing this will automatically update
            // the inner fields at the same time.
            field.Update();

            doc.Save(dataDir + "InsertNestedFields Out.docx");

            Console.WriteLine("\nInserted nested fields in the document successfully.\nFile saved at " + dataDir + "InsertNestedFields Out.docx");
        }
开发者ID:robv8r,项目名称:Aspose_Words_NET,代码行数:32,代码来源:InsertNestedFields.cs

示例7: ClearFormatting

        public void ClearFormatting()
        {
            //ExStart
            //ExFor:DocumentBuilder.PageSetup
            //ExFor:DocumentBuilder.InsertBreak
            //ExFor:DocumentBuilder.Document
            //ExFor:PageSetup
            //ExFor:PageSetup.Orientation
            //ExFor:PageSetup.VerticalAlignment
            //ExFor:PageSetup.ClearFormatting
            //ExFor:Orientation
            //ExFor:PageVerticalAlignment
            //ExFor:BreakType
            //ExSummary:Shows how to insert sections using DocumentBuilder, specify page setup for a section and reset page setup to defaults.
            DocumentBuilder builder = new DocumentBuilder();

            // Modify the first section in the document.
            builder.PageSetup.Orientation = Orientation.Landscape;
            builder.PageSetup.VerticalAlignment = PageVerticalAlignment.Center;
            builder.Writeln("Section 1, landscape oriented and text vertically centered.");

            // Start a new section and reset its formatting to defaults.
            builder.InsertBreak(BreakType.SectionBreakNewPage);
            builder.PageSetup.ClearFormatting();
            builder.Writeln("Section 2, back to default Letter paper size, portrait orientation and top alignment.");

            builder.Document.Save(MyDir + "PageSetup.ClearFormatting Out.doc");
            //ExEnd
        }
开发者ID:nausherwan-aslam,项目名称:Aspose_Words_NET,代码行数:29,代码来源:ExPageSetup.cs

示例8: Main

        public static void Main()
        {
            // The path to the documents directory.
            string dataDir = Path.GetFullPath("../../../Data/");

            //ExStart
            //ExFor:DocumentBuilder.InsertField(string)
            //ExId:DocumentBuilderInsertNestedFields
            //ExSummary:Demonstrates how to insert fields nested within another field using DocumentBuilder.
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert a few page breaks (just for testing)
            for (int i = 0; i < 5; i++)
                builder.InsertBreak(BreakType.PageBreak);

            // Move the DocumentBuilder cursor into the primary footer.
            builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

            // We want to insert a field like this:
            // { IF {PAGE} <> {NUMPAGES} "See Next Page" "Last Page" }
            Field field = builder.InsertField(@"IF ");
            builder.MoveTo(field.Separator);
            builder.InsertField("PAGE");
            builder.Write(" <> ");
            builder.InsertField("NUMPAGES");
            builder.Write(" \"See Next Page\" \"Last Page\" ");

            // Finally update the outer field to recalcaluate the final value. Doing this will automatically update
            // the inner fields at the same time.
            field.Update();

            doc.Save(dataDir + "InsertNestedFields Out.docx");
            //ExEnd
        }
开发者ID:nancyeiceblue,项目名称:Aspose_Words_NET,代码行数:35,代码来源:Program.cs

示例9: HeadersAndFooters

        public static void HeadersAndFooters(string dataDir)
        {
            // ExStart:DocumentBuilderHeadersAndFooters
            // Create a blank document.
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Specify that we want headers and footers different for first, even and odd pages.
            builder.PageSetup.DifferentFirstPageHeaderFooter = true;
            builder.PageSetup.OddAndEvenPagesHeaderFooter = true;

            // Create the headers.
            builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
            builder.Write("Header First");
            builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
            builder.Write("Header Even");
            builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
            builder.Write("Header Odd");

            // Create three pages in the document.
            builder.MoveToSection(0);
            builder.Writeln("Page1");
            builder.InsertBreak(BreakType.PageBreak);
            builder.Writeln("Page2");
            builder.InsertBreak(BreakType.PageBreak);
            builder.Writeln("Page3");

            dataDir = dataDir + "DocumentBuilder.HeadersAndFooters_out.doc";
            doc.Save(dataDir);
            // ExEnd:DocumentBuilderHeadersAndFooters   
            Console.WriteLine("\nHeaders and footers created successfully using DocumentBuilder.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:32,代码来源:DocumentBuilderMovingCursor.cs

示例10: Run

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

            // Create a simple document from scratch.
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);
            builder.Writeln("Test Signed PDF.");

            // Load the certificate from disk.
            // The other constructor overloads can be used to load certificates from different locations.
            X509Certificate2 cert = new X509Certificate2(
                dataDir + "signature.pfx", "signature");

            // Pass the certificate and details to the save options class to sign with.
            PdfSaveOptions options = new PdfSaveOptions();
            options.DigitalSignatureDetails = new PdfDigitalSignatureDetails(
                cert,
                "Test Signing",
                "Aspose Office",
                DateTime.Now);

            dataDir = dataDir + "Document.Signed_out_.pdf";
            // Save the document as PDF with the digital signature set.
            doc.Save(dataDir, options);

            //ExEnd:DigitallySignedPdf
            Console.WriteLine("\nDigitally signed PDF file created successfully.\nFile saved at " + dataDir);
        }
开发者ID:animaal,项目名称:Aspose_Words_NET,代码行数:31,代码来源:DigitallySignedPdf.cs

示例11: Run

        public static void Run()
        {
            // ExStart:ChangeFieldUpdateCultureSource
            // The path to the documents directory.
            string dataDir = RunExamples.GetDataDir_WorkingWithFields();
            // We will test this functionality creating a document with two fields with date formatting
            // ExStart:DocumentBuilderInsertField
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // Insert content with German locale.
            builder.Font.LocaleId = 1031;
            builder.InsertField("MERGEFIELD Date1 \\@ \"dddd, d MMMM yyyy\"");
            builder.Write(" - ");
            builder.InsertField("MERGEFIELD Date2 \\@ \"dddd, d MMMM yyyy\"");
            // ExEnd:DocumentBuilderInsertField
            // Shows how to specify where the culture used for date formatting during field update and mail merge is chosen from.
            // Set the culture used during field update to the culture used by the field.            
            doc.FieldOptions.FieldUpdateCultureSource = FieldUpdateCultureSource.FieldCode;
            doc.MailMerge.Execute(new string[] { "Date2" }, new object[] { new DateTime(2011, 1, 01) });
            dataDir = dataDir + "Field.ChangeFieldUpdateCultureSource_out.doc";
            doc.Save(dataDir);
            // ExEnd:ChangeFieldUpdateCultureSource

            Console.WriteLine("\nCulture changed successfully used in formatting fields during update.\nFile saved at " + dataDir);
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:26,代码来源:ChangeFieldUpdateCultureSource.cs

示例12: Main

        static void Main(string[] args)
        {
            
            Document doc = new Document();
            DocumentBuilder builder = new DocumentBuilder(doc);

            // We call this method to start building the table.
            builder.StartTable();
            builder.InsertCell();
            builder.Write("Row 1, Cell 1 Content.");

            // Build the second cell
            builder.InsertCell();
            builder.Write("Row 1, Cell 2 Content.");
            // Call the following method to end the row and start a new row.
            builder.EndRow();

            // Build the first cell of the second row.
            builder.InsertCell();
            builder.Write("Row 2, Cell 1 Content");

            // Build the second cell.
            builder.InsertCell();
            builder.Write("Row 2, Cell 2 Content.");
            builder.EndRow();

            // Signal that we have finished building the table.
            builder.EndTable();

            // Save the document to disk.
            doc.Save("DocumentBuilder.CreateSimpleTable Out.doc");
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:32,代码来源:Program.cs

示例13: CreateFloatingPositionSize

        public void CreateFloatingPositionSize()
        {
            //ExStart
            //ExFor:ShapeBase.Left
            //ExFor:ShapeBase.Top
            //ExFor:ShapeBase.Width
            //ExFor:ShapeBase.Height
            //ExFor:DocumentBuilder.CurrentSection
            //ExFor:PageSetup.PageWidth
            //ExSummary:Shows how to insert a floating image and specify its position and size.
            // This creates a builder and also an empty document inside the builder.
            DocumentBuilder builder = new DocumentBuilder();

            // By default, the image is inline.
            Shape shape = builder.InsertImage(ExDir + "Hammer.wmf");

            // Make the image float, put it behind text and center on the page.
            shape.WrapType = WrapType.None;

            // Make position relative to the page.
            shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
            shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;

            // Make the shape occupy a band 50 points high at the very top of the page.
            shape.Left = 0;
            shape.Top = 0;
            shape.Width = builder.CurrentSection.PageSetup.PageWidth;
            shape.Height = 50;

            builder.Document.Save(ExDir + "Image.CreateFloatingPositionSize Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:32,代码来源:ExImage.cs

示例14: CreateFloatingPageCenter

        public void CreateFloatingPageCenter()
        {
            //ExStart
            //ExFor:DocumentBuilder.InsertImage(string)
            //ExFor:Shape
            //ExFor:ShapeBase
            //ExFor:ShapeBase.WrapType
            //ExFor:ShapeBase.BehindText
            //ExFor:ShapeBase.RelativeHorizontalPosition
            //ExFor:ShapeBase.RelativeVerticalPosition
            //ExFor:ShapeBase.HorizontalAlignment
            //ExFor:ShapeBase.VerticalAlignment
            //ExFor:WrapType
            //ExFor:RelativeHorizontalPosition
            //ExFor:RelativeVerticalPosition
            //ExFor:HorizontalAlignment
            //ExFor:VerticalAlignment
            //ExSummary:Shows how to insert a floating image in the middle of a page.
            // This creates a builder and also an empty document inside the builder.
            DocumentBuilder builder = new DocumentBuilder();

            // By default, the image is inline.
            Shape shape = builder.InsertImage(ExDir + "Aspose.Words.gif");

            // Make the image float, put it behind text and center on the page.
            shape.WrapType = WrapType.None;
            shape.BehindText = true;
            shape.RelativeHorizontalPosition = RelativeHorizontalPosition.Page;
            shape.HorizontalAlignment = HorizontalAlignment.Center;
            shape.RelativeVerticalPosition = RelativeVerticalPosition.Page;
            shape.VerticalAlignment = VerticalAlignment.Center;

            builder.Document.Save(ExDir + "Image.CreateFloatingPageCenter Out.doc");
            //ExEnd
        }
开发者ID:joyang1,项目名称:Aspose_Words_NET,代码行数:35,代码来源:ExImage.cs

示例15: DifferentHeaders

        public void DifferentHeaders()
        {
            //ExStart
            //ExFor:PageSetup.DifferentFirstPageHeaderFooter
            //ExFor:PageSetup.OddAndEvenPagesHeaderFooter
            //ExSummary:Creates headers and footers different for first, even and odd pages using DocumentBuilder.
            DocumentBuilder builder = new DocumentBuilder();

            PageSetup ps = builder.PageSetup;
            ps.DifferentFirstPageHeaderFooter = true;
            ps.OddAndEvenPagesHeaderFooter = true;

            builder.MoveToHeaderFooter(HeaderFooterType.HeaderFirst);
            builder.Writeln("First page header.");

            builder.MoveToHeaderFooter(HeaderFooterType.HeaderEven);
            builder.Writeln("Even pages header.");

            builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
            builder.Writeln("Odd pages header.");

            // Move back to the main story of the first section.
            builder.MoveToSection(0);
            builder.Writeln("Text page 1.");
            builder.InsertBreak(BreakType.PageBreak);
            builder.Writeln("Text page 2.");
            builder.InsertBreak(BreakType.PageBreak);
            builder.Writeln("Text page 3.");

            builder.Document.Save(MyDir + @"\Artifacts\PageSetup.DifferentHeaders.doc");
            //ExEnd
        }
开发者ID:aspose-words,项目名称:Aspose.Words-for-.NET,代码行数:32,代码来源:ExPageSetup.cs


注:本文中的DocumentBuilder类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。