示例#1
0
        /// <summary>
        /// How to edit Page Numbering in an existing DOCX document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/edit-page-numbering-in-docx-document-net-csharp-vb.php
        /// </remarks>
        public static void EditPageNumbering()
        {
            // Modify the Page Numbering from: "Page N of M" to "Página N".
            string inpFile = @"..\..\PageNumbering.docx";
            string outFile = @"PageNumbering-modified.pdf";

            // Load a DOCX document with Page Numbering (PageNumbering.docx).
            DocumentCore dc = DocumentCore.Load(inpFile);
            Section      s  = dc.Sections[0];

            foreach (HeaderFooter hf in s.HeadersFooters)
            {
                foreach (Field field in hf.GetChildElements(true, ElementType.Field).Reverse())
                {
                    // Page numbering is a Field,
                    // so we have to find the fields with the type Page or NumPages and remove.
                    if (field.FieldType == FieldType.Page || field.FieldType == FieldType.NumPages)
                    {
                        // Save the paragraph containing the page numbering and character formatting.
                        Paragraph       parWithNumbering = null;
                        CharacterFormat cf = field.CharacterFormat.Clone();

                        // Also assume that our page numbering located in a paragraph,
                        // so let's remove the paragraph's content too.
                        if (field.Parent is Paragraph)
                        {
                            parWithNumbering = (field.Parent as Paragraph);
                            // If we'll delete only the fields (field.Content.Delete()), our paragraph
                            // may contain text "Page of ".
                            // Based on this, we remove all items in this paragraph.
                            // Fields {Page} and {NumPages} will be also deleted here, because they are Inlines too.
                            parWithNumbering.Inlines.Clear();
                        }

                        if (parWithNumbering != null)
                        {
                            // Insert new Page Numbering: "Página N":
                            // Insert "Página ".
                            parWithNumbering.Inlines.Add(new Run(dc, "Página ", cf.Clone()));
                            // Insert field {Page}.
                            Field fPage = new Field(dc, FieldType.Page);
                            fPage.CharacterFormat = cf.Clone();
                            parWithNumbering.Inlines.Add(fPage);
                        }
                    }
                }
            }
            dc.Save(outFile);

            // Open the results for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(inpFile)
            {
                UseShellExecute = true
            });
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
            {
                UseShellExecute = true
            });
        }
示例#2
0
        /// <summary>
        /// Add page numbering into an existing PDF document.
        /// </summary>
        /// <remarks>
        /// https://www.sautinsoft.com/products/document/help/net/developer-guide/add-page-numbering-in-pdf-net-csharp-vb.php
        /// </remarks>
        static void AddPageNumbering()
        {
            string       inpFile = @"..\..\shrek.pdf";
            string       outFile = @"With Pages.pdf";
            DocumentCore dc      = DocumentCore.Load(inpFile);

            // We place our page numbers into the footer.
            // Therefore we've to create a footer.
            HeaderFooter footer = new HeaderFooter(dc, HeaderFooterType.FooterDefault);

            // Create a new paragraph to insert a page numbering.
            // So that, our page numbering looks as: Page N of M.
            Paragraph par = new Paragraph(dc);

            par.ParagraphFormat.Alignment = HorizontalAlignment.Right;
            CharacterFormat cf = new CharacterFormat()
            {
                FontName = "Consolas", Size = 14.0
            };

            par.Content.Start.Insert("Page ", cf.Clone());

            // Page numbering is a Field.
            // Create two fields: FieldType.Page and FieldType.NumPages.
            Field fPage = new Field(dc, FieldType.Page);

            fPage.CharacterFormat = cf.Clone();
            par.Content.End.Insert(fPage.Content);
            par.Content.End.Insert(" of ", cf.Clone());
            Field fPages = new Field(dc, FieldType.NumPages);

            fPages.CharacterFormat = cf.Clone();
            par.Content.End.Insert(fPages.Content);
            footer.Blocks.Add(par);

            foreach (Section s in dc.Sections)
            {
                s.HeadersFooters.Add(footer.Clone(true));
            }
            dc.Save(outFile);

            // Open the results for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(inpFile)
            {
                UseShellExecute = true
            });
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile)
            {
                UseShellExecute = true
            });
        }
示例#3
0
    private static CharacterFormat smethod_0(CharacterFormat A_0)
    {
        CharacterFormat format = (CharacterFormat)A_0.Clone();

        format.Remove(50);
        return(format);
    }
示例#4
0
    private void imethod_15(CharacterFormat A_0, FieldType A_1)
    {
        Field     field;
        FieldType type = A_1;

        if (type <= FieldType.FieldMergeField)
        {
            if (type != FieldType.FieldIf)
            {
                if (type != FieldType.FieldMergeField)
                {
                    goto Label_0044;
                }
                field = new MergeField(this.document_0);
            }
            else
            {
                field = new IfField(this.document_0);
            }
            goto Label_007A;
        }
        switch (type)
        {
        case FieldType.FieldFormTextInput:
            field = new TextFormField(this.document_0);
            goto Label_007A;

        case FieldType.FieldFormCheckBox:
            field = new CheckBoxFormField(this.document_0);
            goto Label_007A;

        case FieldType.FieldFormDropDown:
            field = new DropDownFormField(this.document_0);
            goto Label_007A;
        }
Label_0044:
        field = new Field(this.document_0);
Label_007A:
        this.fieldCharType_0  = FieldCharType.Begin;
        field.Type            = A_1;
        field.CharacterFormat = (CharacterFormat)A_0.Clone();
        this.documentObject_0.method_13(field);
        if (A_1 == FieldType.FieldTOC)
        {
            (this.documentObject_0 as Paragraph).IsTOCPara = true;
        }
        this.stack_0.Push(field);
    }
示例#5
0
        /// <summary>
        /// Creates a simple RTF document.
        /// </summary>
        public static void CreateRtf()
        {
            // Working directory
            string workingDir  = Path.GetFullPath(Directory.GetCurrentDirectory() + @"..\..\..\..\..\..\Testing Files");
            string rtfFilePath = Path.Combine(workingDir, "Result.rtf");

            // Let's create a simple RTF document.
            DocumentCore rtf = new DocumentCore();
            //DocumentCore.Serial = "put your serial here";

            // Add new section.
            Section section = new Section(rtf);

            rtf.Sections.Add(section);

            // Let's set page size A4.
            section.PageSetup.PaperType = PaperType.A4;

            // Add two paragraphs using different ways:

            // Way 1: Add 1st paragraph.
            section.Blocks.Add(new Paragraph(rtf, "This is a first line in 1st paragraph!"));
            Paragraph par1 = section.Blocks[0] as Paragraph;

            par1.ParagraphFormat.Alignment = HorizontalAlignment.Center;

            // Let's add a second line.
            par1.Inlines.Add(new SpecialCharacter(rtf, SpecialCharacterType.LineBreak));
            par1.Inlines.Add(new Run(rtf, "Let's type a second line."));

            // Let's change font name, size and color.
            CharacterFormat cf = new CharacterFormat()
            {
                FontName = "Verdana", Size = 16, FontColor = Color.Orange
            };

            foreach (Inline inline in par1.Inlines)
            {
                if (inline is Run)
                {
                    (inline as Run).CharacterFormat = cf.Clone();
                }
            }

            // Way 2 (easy): Add 2nd paragarph using another way.
            rtf.Content.End.Insert("\nThis is a first line in 2nd paragraph.", new CharacterFormat()
            {
                Size = 25, FontColor = Color.Blue, Bold = true
            });
            SpecialCharacter lBr = new SpecialCharacter(rtf, SpecialCharacterType.LineBreak);

            rtf.Content.End.Insert(lBr.Content);
            rtf.Content.End.Insert("This is a second line.", new CharacterFormat()
            {
                Size = 20, FontColor = Color.DarkGreen, UnderlineStyle = UnderlineType.Single
            });

            // Save RTF to a file
            rtf.Save(rtfFilePath, SaveOptions.RtfDefault);

            // Open the result for demonstation purposes.
            System.Diagnostics.Process.Start(rtfFilePath);
        }
示例#6
0
        static void Main(string[] args)
        {
            XmlTextReader reader = new XmlTextReader(Template.PathXml);

            XmlTag top    = new XmlTag("XML");
            XmlTag target = top;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    target = target.CreateChild(reader.Name);
                    break;

                case XmlNodeType.Text:
                    target.Text = reader.Value;
                    break;

                case XmlNodeType.EndElement:
                    target = target.Parent;
                    break;
                }
            }
            top = top.Childs[0];


            docx = new DocumentCore();

            // Add a new section
            section = new Section(docx);
            section.PageSetup.PageWidth   = LengthUnitConverter.Convert(8.5, LengthUnit.Inch, LengthUnit.Point);
            section.PageSetup.PageHeight  = LengthUnitConverter.Convert(11.0, LengthUnit.Inch, LengthUnit.Point);
            section.PageSetup.Orientation = Orientation.Portrait;
            section.PageSetup.PageMargins = new PageMargins()
            {
                Top    = LengthUnitConverter.Convert(.5f, LengthUnit.Inch, LengthUnit.Point),
                Right  = LengthUnitConverter.Convert(.5f, LengthUnit.Inch, LengthUnit.Point),
                Bottom = LengthUnitConverter.Convert(.5f, LengthUnit.Inch, LengthUnit.Point),
                Left   = LengthUnitConverter.Convert(.5f, LengthUnit.Inch, LengthUnit.Point)
            };

            docx.Sections.Add(section);
            docx.Styles.Add(Template.StyleBullet);

            Table table = new Table(docx);

            table.TableFormat.PreferredWidth = new TableWidth(100, TableWidthUnit.Percentage);
            section.Blocks.Add(table);

            Config config = new Config(top.Childs[0]);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            table.Rows.Add(new ContentName().Content(docx));
            table.Rows.Add(new ContentContact(top.Childs[1].Childs).Content(docx));
            table.Rows.Add(new TableRow(docx, new TableCell(docx, Template.LineBreak(docx))));

            if (config.Summary != null)
            {
                table.Rows.Add(new ContentHeading().Content(docx, "SUMMARY"));
                table.Rows.Add(new ContentSummary(top.Childs[2].Childs, config.Summary).Content(docx));
                table.Rows.Add(new TableRow(docx, new TableCell(docx, Template.LineBreak(docx))));
            }

            if (config.Experience != null)
            {
                table.Rows.Add(new ContentHeading().Content(docx, "WORK AND RELATED EXPERIENCE"));//////////////////////////////////////////////////////////////
                foreach (TableRow item in new ContentExperience(top.Childs[3].Childs, config.Experience).Content(docx, true))
                {
                    table.Rows.Add(item);
                }
                table.Rows.Add(new TableRow(docx, new TableCell(docx, Template.LineBreak(docx))));
            }

            if (config.Education != null)
            {
                table.Rows.Add(new ContentHeading().Content(docx, "EDUCATION"));//////////////////////////////////////////////////////////////
                foreach (TableRow item in new ContentEducation(top.Childs[4].Childs, config.Education).Content(docx))
                {
                    table.Rows.Add(item);
                }
                table.Rows.Add(new TableRow(docx, new TableCell(docx, Template.LineBreak(docx))));
            }

            if (config.Skill != null)
            {
                table.Rows.Add(new ContentHeading().Content(docx, "SKILLS"));//////////////////////////////////////////////////////////////
                TableRow row = new TableRow(docx, new TableCell(docx), new TableCell(docx));
                table.Rows.Add(row);
                foreach (TableCell cell in row.Cells)
                {
                    cell.CellFormat.PreferredWidth = new TableWidth(50, TableWidthUnit.Auto);
                    cell.ColumnSpan = 1;
                }

                List <Table> area = new ContentSkill(top.Childs[6].Childs, config.Skill, 4).Content(docx);
                for (int i = 0; i < area.Count; i++)
                {
                    if (i - 1 < ContentSkill.breakNumber)
                    {
                        row.Cells[0].Blocks.Add(area[i]);
                    }
                    else
                    {
                        row.Cells[1].Blocks.Add(area[i]);
                    }
                }
                table.Rows.Add(new TableRow(docx, new TableCell(docx, Template.LineBreak(docx))));
            }

            if (config.Award != null)
            {
                table.Rows.Add(new ContentHeading().Content(docx, "AWARDS AND HONOURS"));//////////////////////////////////////////////////////////////
                foreach (TableRow item in new ContentAwards(top.Childs[5].Childs, config.Award).Content(docx))
                {
                    table.Rows.Add(item);
                }
                table.Rows.Add(new TableRow(docx, new TableCell(docx, Template.LineBreak(docx))));
            }

            if (config.Volunteer != null)
            {
                table.Rows.Add(new ContentHeading().Content(docx, "VOLUNTEER ACTIVITIES"));//////////////////////////////////////////////////////////////
                foreach (TableRow item in new ContentExperience(top.Childs[7].Childs, config.Volunteer).Content(docx, false))
                {
                    table.Rows.Add(item);
                }
                table.Rows.Add(new TableRow(docx, new TableCell(docx, Template.LineBreak(docx))));
            }


            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            HeaderFooter footer = new HeaderFooter(docx, HeaderFooterType.FooterDefault);

            // Create a new paragraph to insert a page numbering.
            // So that, our page numbering looks as: Page N of M.
            Paragraph par = new Paragraph(docx);

            par.ParagraphFormat.Alignment = HorizontalAlignment.Center;
            CharacterFormat cf = Template.FormatNormal.cFormat;

            par.Content.Start.Insert("Page ", cf.Clone());

            // Page numbering is a Field.
            // Create two fields: FieldType.Page and FieldType.NumPages.
            Field fPage = new Field(docx, FieldType.Page);

            fPage.CharacterFormat = cf.Clone();
            par.Content.End.Insert(fPage.Content);
            par.Content.End.Insert(" of ", cf.Clone());
            par.Content.End.Insert(new Field(docx, FieldType.NumPages).Content);
            par.Content.End.Insert(" - Generated by Jimmy Vo", cf.Clone());

            // Add the paragraph with Fields into the footer.
            footer.Blocks.Add(par);

            // Add the footer into the section.
            section.HeadersFooters.Add(footer);

            docx.Save(Template.PathOutput);

            System.Diagnostics.Process.Start(Path.Combine(Directory.GetCurrentDirectory(), Template.PathOutput));
        }
示例#7
0
        /// <summary>
        /// Creates a simple Docx document.
        /// </summary>
        public static void CreateDocx()
        {
            // Set a path to our docx file.
            string docxPath = @"..\..\..\..\..\Testing Files\Result.docx";

            // Let's create a simple DOCX document.
            DocumentCore docx = new DocumentCore();
            //DocumentCore.Serial = "put your serial here";

            // Add new section.
            Section section = new Section(docx);

            docx.Sections.Add(section);

            // Let's set page size A4.
            section.PageSetup.PaperType = PaperType.A4;

            // Add two paragraphs using different ways:

            // Way 1: Add 1st paragraph.
            section.Blocks.Add(new Paragraph(docx, "This is a first line in 1st paragraph!"));
            Paragraph par1 = section.Blocks[0] as Paragraph;

            par1.ParagraphFormat.Alignment = HorizontalAlignment.Center;

            // Let's add a second line.
            par1.Inlines.Add(new SpecialCharacter(docx, SpecialCharacterType.LineBreak));
            par1.Inlines.Add(new Run(docx, "Let's type a second line."));

            // Let's change font name, size and color.
            CharacterFormat cf = new CharacterFormat()
            {
                FontName = "Verdana", Size = 16, FontColor = Color.Orange
            };

            foreach (Inline inline in par1.Inlines)
            {
                if (inline is Run)
                {
                    (inline as Run).CharacterFormat = cf.Clone();
                }
            }

            // Way 2 (easy): Add 2nd paragarph using another way.
            docx.Content.End.Insert("\nThis is a first line in 2nd paragraph.", new CharacterFormat()
            {
                Size = 25, FontColor = Color.Blue, Bold = true
            });
            SpecialCharacter lBr = new SpecialCharacter(docx, SpecialCharacterType.LineBreak);

            docx.Content.End.Insert(lBr.Content);
            docx.Content.End.Insert("This is a second line.", new CharacterFormat()
            {
                Size = 20, FontColor = Color.DarkGreen, UnderlineStyle = UnderlineType.Single
            });

            // Save DOCX to a file
            docx.Save(docxPath);

            // Open the result for demonstation purposes.
            System.Diagnostics.Process.Start(docxPath);
        }
        private void addhaederfooter()
        {
            string taskid = HttpContext.Current.Session["Name"].ToString();

            HttpContext.Current.Session.Timeout = 60;
            string inputfile  = System.Web.HttpContext.Current.Server.MapPath("~/storepdf/" + taskid + ".pdf");
            string outputfile = System.Web.HttpContext.Current.Server.MapPath("~/editorpdf/" + taskid + ".pdf");
            //string pictPath = "~/img/caslab.jpg";
            DocumentCore dc     = DocumentCore.Load(inputfile);
            HeaderFooter header = new HeaderFooter(dc, HeaderFooterType.HeaderDefault);

            SautinSoft.Document.Paragraph par1 = new SautinSoft.Document.Paragraph(dc);
            par1.ParagraphFormat.Alignment = HorizontalAlignment.Left;
            //header.Content.Start.Insert("CASLAB", new CharacterFormat() { Size = 15.0, FontColor = Color.Blue });
            CharacterFormat cf1 = new CharacterFormat()
            {
                FontName = "Consolas", Size = 15.0, FontColor = Color.Blue
            };

            par1.Content.Start.Insert("CASLAB", cf1.Clone());
            header.Blocks.Add(par1);
            SautinSoft.Document.Paragraph par2 = new SautinSoft.Document.Paragraph(dc);
            par2.ParagraphFormat.Alignment = HorizontalAlignment.Right;
            //header.Content.Start.Insert("CASLAB", new CharacterFormat() { Size = 15.0, FontColor = Color.Blue });
            CharacterFormat cf2 = new CharacterFormat()
            {
                FontName = "Consolas", Size = 15.0
            };

            par2.Content.Start.Insert(taskid, cf2.Clone());
            header.Blocks.Add(par2);
            SautinSoft.Document.Paragraph par = new SautinSoft.Document.Paragraph(dc);
            par.ParagraphFormat.Alignment = HorizontalAlignment.Right;
            CharacterFormat cf = new CharacterFormat()
            {
                FontName = "Consolas", Size = 12.0
            };

            par.Content.Start.Insert("Page", cf.Clone());
            Field fPage = new Field(dc, FieldType.Page);

            fPage.CharacterFormat = cf.Clone();
            par.Content.End.Insert(fPage.Content);
            par.Content.End.Insert(" of ", cf.Clone());
            Field fPages = new Field(dc, FieldType.NumPages);

            fPages.CharacterFormat = cf.Clone();

            //header.Content.Start.Insert(taskid, new CharacterFormat() { Size = 15.0, FontColor = Color.Black });
            par.Content.End.Insert(fPages.Content);

            header.Blocks.Add(par);
            SautinSoft.Document.Paragraph par3 = new SautinSoft.Document.Paragraph(dc);
            par3.ParagraphFormat.Alignment = HorizontalAlignment.Center;
            //header.Content.Start.Insert("CASLAB", new CharacterFormat() { Size = 15.0, FontColor = Color.Blue });
            CharacterFormat cf3 = new CharacterFormat();

            par3.Content.Start.Insert("______________________________________________________________________________________________", cf3.Clone());
            header.Blocks.Add(par3);
            //Picture pict1 = new Picture(dc, InlineLayout.Inline(new Size(100, 100)), pictPath);

            foreach (SautinSoft.Document.Section s in dc.Sections)
            {
                s.HeadersFooters.Add(header.Clone(true));
            }
            HeaderFooter footer = new HeaderFooter(dc, HeaderFooterType.FooterDefault);

            SautinSoft.Document.Paragraph par4 = new SautinSoft.Document.Paragraph(dc);
            par4.ParagraphFormat.Alignment = HorizontalAlignment.Center;
            //header.Content.Start.Insert("CASLAB", new CharacterFormat() { Size = 15.0, FontColor = Color.Blue });
            CharacterFormat cf4 = new CharacterFormat();

            par4.Content.Start.Insert("______________________________________________________________________________________________", cf4.Clone());
            footer.Blocks.Add(par4);
            par4.Content.End.Insert("This document and all the information contained here are confidential and exclusive  property of CASLAB and maynot be reproduced,disclosed,or made public in any manner prior to express written authorization by CASLAB.", new CharacterFormat()
            {
                Size = 12.0, FontColor = Color.Black
            });
            foreach (SautinSoft.Document.Section s in dc.Sections)
            {
                s.HeadersFooters.Add(footer.Clone(true));
            }
            dc.Save(outputfile);
        }
示例#9
0
 internal static DocumentObject[] smethod_1(DocumentBase A_0, CharacterFormat A_1, FieldType A_2, string A_3)
 {
     return(new DocumentObject[] { new Field((IDocument)A_0, A_2, A_3), new FieldMark((IDocument)A_0, (CharacterFormat)A_1.Clone(), FieldMarkType.FieldSeparator), new TextRange((IDocument)A_0, BookmarkStart.b("瘭栯樱", 8), (CharacterFormat)A_1.Clone()), new FieldMark((IDocument)A_0, (CharacterFormat)A_1.Clone(), FieldMarkType.FieldEnd) });
 }
示例#10
0
        // How to add a page numbering in a document.
        public static void AddPageNumbering()
        {
            string documentPath = @"PageNumbering.docx";

            // Let's create a new document with multiple pages.
            DocumentCore dc = new DocumentCore();

            string[] pagesText = new string[] { "One", "Two", "Three", "Four", "Five" };
            Random   r         = new Random();

            // Create a new section.
            Section section = new Section(dc);

            dc.Sections.Add(section);

            // We place our page numbers into the footer.
            // Therefore we've to create a footer.
            HeaderFooter footer = new HeaderFooter(dc, HeaderFooterType.FooterDefault);

            // Create a new paragraph to insert a page numbering.
            // So that, our page numbering looks as: Page N of M.
            Paragraph par = new Paragraph(dc);

            par.ParagraphFormat.Alignment = HorizontalAlignment.Center;
            CharacterFormat cf = new CharacterFormat()
            {
                FontName = "Arial", Size = 12.0
            };

            par.Content.Start.Insert("Page ", cf.Clone());

            // Page numbering is a Field.
            // Create two fields: FieldType.Page and FieldType.NumPages.
            Field fPage = new Field(dc, FieldType.Page);

            fPage.CharacterFormat = cf.Clone();
            par.Content.End.Insert(fPage.Content);
            par.Content.End.Insert(" of ", cf.Clone());
            Field fPages = new Field(dc, FieldType.NumPages);

            fPages.CharacterFormat = cf.Clone();
            par.Content.End.Insert(fPages.Content);

            // Add the paragraph with Fields into the footer.
            footer.Blocks.Add(par);

            // Add the footer into the section.
            section.HeadersFooters.Add(footer);

            // Add some paragraphs with page breaks in the document,
            // to make several pages.
            foreach (string text in pagesText)
            {
                Paragraph p = new Paragraph(dc);
                p.ParagraphFormat.Alignment = HorizontalAlignment.Center;
                section.Blocks.Add(p);

                int color = r.Next(0x000000, 0xFFFFFF);
                p.Content.Start.Insert(text, new CharacterFormat()
                {
                    FontName = "Arial", Size = 72.0, FontColor = new Color(color)
                });
                p.Content.End.Insert(new SpecialCharacter(dc, SpecialCharacterType.PageBreak).Content);
            }

            // Save our document into DOCX file.
            dc.Save(documentPath);

            // Open the result for demonstation purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(documentPath)
            {
                UseShellExecute = true
            });
        }
示例#11
0
    private void method_14(CharacterFormat A_0, Class1107 A_1, Class537 A_2, int A_3, ref int A_4, bool A_5)
    {
        if ((!A_1.bool_0 && (A_4 == 1)) && (A_2.method_2()[A_3] == '\x0015'))
        {
            A_1.bool_0 = true;
        }
        int  num2 = A_3;
        int  num  = A_3;
        int  num3 = A_3 + A_4;
        int  num6 = A_4;
        bool flag = false;
        int  num5 = A_2.method_0(num) - num;

        while (num < num3)
        {
            int num4 = num + num5;
            if ((this.class130_0.method_1() == num4) || (this.class130_1.method_1() == num4))
            {
                flag = true;
            }
            char ch = A_2.method_2()[num];
            if (((((ch != '\b') && !A_1.bool_0) && ((this.class132_0.method_1() != num4) && (this.class136_0.method_1() != num4))) && (((this.class135_0.method_1() != num4) && (this.class133_0.method_1() != num4)) && ((this.class131_0.method_1() != num4) && (this.class134_0.method_1() != num4)))) && ((this.class129_0.method_1() != num4) && !flag))
            {
                if (A_5 || (ch.ToString().IndexOfAny(Class818.char_20) <= -1))
                {
                    goto Label_0290;
                }
                if (num == num2)
                {
                    num++;
                }
                A_4 = num - num2;
                break;
            }
            CharacterFormat format = (CharacterFormat)A_0.Clone();
            if (!A_1.bool_0 && (num > num2))
            {
                this.method_15(format, A_1, A_2, num2, num - num2);
                num2 = num;
            }
            this.class132_0.method_2(num4);
            if (this.class135_0.method_1() == this.class136_0.method_1())
            {
                this.class136_0.method_2(num4);
                this.class135_0.method_2(num4);
                this.class133_0.method_2(num4);
            }
            else
            {
                this.class135_0.method_2(num4);
                this.class133_0.method_2(num4);
                this.class136_0.method_2(num4);
            }
            this.class131_0.method_2(num4);
            this.class134_0.method_2(num4);
            this.class129_0.method_2(num4);
            if (flag)
            {
                FootnoteType type;
                flag = false;
                if (this.class130_0.method_1() == num4)
                {
                    this.class130_0.method_2(num4);
                }
                else
                {
                    this.class130_1.method_2(num4);
                }
                Class762 class2 = this.method_25(num4, out type);
                if ((class2 != null) && this.method_26(class2, type, A_2, num, num3, A_1, format))
                {
                    num2 = num3;
                }
            }
            else if ((A_1.bool_0 && ((A_4 == 1) || (Array.IndexOf <char>(Class818.char_22, ch) > -1))) || (ch == '\b'))
            {
                if (((A_4 > 1) && (num > num2)) && (Array.IndexOf <char>(Class818.char_22, ch) > -1))
                {
                    this.method_15(format, A_1, A_2, num2, num - num2);
                }
                this.method_17(ch, num4, format, A_1);
                num2 = num + 1;
            }
Label_0290:
            num++;
        }
        if (A_5)
        {
            num--;
        }
        if (num > num2)
        {
            this.method_15(A_0, A_1, A_2, num2, num - num2);
            A_4 = (A_4 < num6) ? (num - A_3) : A_4;
        }
    }
示例#12
0
        /// <summary>
        /// Update table of contents in word document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/update-table-of-contents-in-word-document-net-csharp-vb.php
        /// </remarks>
        public static void TOC()
        {
            string pathFile   = @"..\..\toc.docx";
            string resultFile = "UpdatedTOC.docx";

            // Load a .docx document with TOC.
            DocumentCore dc = DocumentCore.Load(pathFile);

            Paragraph p = new Paragraph(dc);

            p.Content.Start.Insert("I was born in the year 1632, in the city of York, of a good family, though not of that country, " +
                                   "my father being a foreigner of Bremen, who settled first at Hull.  He got a good estate by merchandise, and leaving " +
                                   "off his trade, lived afterwards at York, from whence he had married my mother, whose relations were named Robinson, " +
                                   "a very good family in that country, and from whom I was called Robinson Kreutznaer; but, by the usual corruption " +
                                   "of words in England, we are now called-nay we call ourselves and write our name-Crusoe; and so my companions always " +
                                   "called me. I had two elder brothers, one of whom was lieutenant-colonel to an English regiment of foot in Flanders, " +
                                   "formerly commanded by the famous Colonel Lockhart, and was killed at the battle near Dunkirk against the Spaniards.",

                                   new CharacterFormat()
            {
                Size = 28
            });
            p.ParagraphFormat.Alignment = HorizontalAlignment.Justify;

            // Insert the paragraph as 6th element in the 1st section.
            dc.Sections[0].Blocks.Insert(5, p);

            Paragraph p1 = new Paragraph(dc);

            p1.Content.Start.Insert("That evil influence which carried me first away from my father’s house-which hurried me into the " +
                                    "wild and indigested notion of raising my fortune, and that impressed those conceits so forcibly upon me as to make me " +
                                    "deaf to all good advice, and to the entreaties and even the commands of my father-I say, the same influence, whatever " +
                                    "it was, presented the most unfortunate of all enterprises to my view; and I went on board a vessel bound to the coast " +
                                    "of Africa; or, as our sailors vulgarly called it, a voyage to Guinea. It was my great misfortune that in all these " +
                                    "adventures I did not ship myself as a sailor; when, though I might indeed have worked a little harder than ordinary, " +
                                    "yet at the same time I should have learnt the duty and office of a fore-mast man, and in time might have qualified " +
                                    "myself for a mate or lieutenant, if not for a master.  But as it was always my fate to choose for the worse, so I did " +
                                    "here; for having money in my pocket and good clothes upon my back, I would always go on board in the habit of " +
                                    "a gentleman; and so I neither had any business in the ship, nor learned to do any.",

                                    new CharacterFormat()
            {
                Size = 28
            });
            p1.ParagraphFormat.Alignment = HorizontalAlignment.Justify;

            // Insert the paragraph as 10th element in the 1st section.
            dc.Sections[0].Blocks.Insert(9, p1);

            // Update TOC (TOC can be updated only after all document content is added).
            TableOfEntries toc = (TableOfEntries)dc.GetChildElements(true, ElementType.TableOfEntries).FirstOrDefault();

            toc.Update();

            // Update TOC's page numbers.
            // Page numbers are automatically updated in that case.
            dc.GetPaginator(new PaginatorOptions()
            {
                UpdateFields = true
            });

            // Change default character formatting for all text inside TOC
            CharacterFormat cf = new CharacterFormat();

            cf.Size      = 20;
            cf.FontColor = Color.Blue;
            foreach (Inline inline in toc.GetChildElements(true, ElementType.Run, ElementType.SpecialCharacter))
            {
                if (inline is Run)
                {
                    ((Run)inline).CharacterFormat = cf.Clone();
                }
                else
                {
                    ((SpecialCharacter)inline).CharacterFormat = cf.Clone();
                }
            }

            // Save the document as new DOCX file.
            dc.Save(resultFile);
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultFile)
            {
                UseShellExecute = true
            });
        }
        public void CreatePieChartsPage(DocumentCore dc)
        {
            // 1. Add new Section (for the charts) at the beginning of the report.
            Section sectCharts = new Section(dc);

            sectCharts.PageSetup             = dc.Sections[0].PageSetup.Clone();
            sectCharts.PageSetup.PageMargins = new PageMargins()
            {
                Left  = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                Right = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point),
                Top   = LengthUnitConverter.Convert(5, LengthUnit.Millimeter, LengthUnit.Point)
            };

            dc.Sections.Insert(0, sectCharts);

            Paragraph pageHeading = new Paragraph(dc, new Run(dc, "Statistics", new CharacterFormat()
            {
                FontName       = "Calibri",
                Size           = 42,
                Bold           = true,
                UnderlineStyle = UnderlineType.Single,
                Italic         = true,
                FontColor      = new Color(244, 176, 131),
                AllCaps        = true
            }));

            pageHeading.ParagraphFormat.Alignment = SautinSoft.Document.HorizontalAlignment.Center;
            sectCharts.Blocks.Add(pageHeading);

            CharacterFormat cf = new CharacterFormat()
            {
                FontName       = "Calibri",
                Size           = 20,
                UnderlineStyle = UnderlineType.Single,
                FontColor      = new Color(244, 176, 131),
            };

            Paragraph recipentHeading = new Paragraph(dc, new Run(dc, "Income from the customers in percentages:",
                                                                  cf.Clone()));

            sectCharts.Blocks.Add(recipentHeading);

            Paragraph itemHeading = new Paragraph(dc, new Run(dc, "Sales overview - see the best selling product:", cf.Clone()));

            Shape shpItem = new Shape(dc, new FloatingLayout(new HorizontalPosition(5f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                                                             new VerticalPosition(130f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                                                             new SautinSoft.Document.Drawing.Size(200, 20, LengthUnit.Millimeter)));

            shpItem.Outline.Fill.SetEmpty();
            shpItem.Text.Blocks.Add(itemHeading);
            sectCharts.Content.Start.Insert(shpItem.Content);

            // 2. Add Chart - Recipients
            // Create dictionary for the chart <Recipient Name, Total Percentage>.
            Dictionary <string, double> recipients = new Dictionary <string, double>();
            double totalAmount = Orders.Sum(o => o.OrderTotal);

            foreach (Order o in Orders)
            {
                if (recipients.Keys.Contains(o.Recipient))
                {
                    recipients[o.Recipient] += o.OrderTotal * 100 / totalAmount;
                }
                else
                {
                    recipients.Add(o.Recipient, o.OrderTotal * 100 / totalAmount);
                }
                recipients[o.Recipient] = Math.Round(recipients[o.Recipient]);
            }
            FloatingLayout flR = new FloatingLayout(new HorizontalPosition(20f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                                                    new VerticalPosition(40f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                                                    new SautinSoft.Document.Drawing.Size(200, 200));

            AddPieChart(sectCharts, flR, recipients, true, "%", true, true);

            // 3. Add Chart - Best selling item
            // Create dictionary for the chart <Product Name, Total>.
            Dictionary <string, double> productSales = new Dictionary <string, double>();

            foreach (Order o in Orders)
            {
                foreach (Product p in o.Products)
                {
                    if (productSales.Keys.Contains(p.Name))
                    {
                        productSales[p.Name] += p.TotalPrice;
                    }
                    else
                    {
                        productSales.Add(p.Name, p.TotalPrice);
                    }
                }
            }

            FloatingLayout flP = new FloatingLayout(new HorizontalPosition(20f, LengthUnit.Millimeter, HorizontalPositionAnchor.LeftMargin),
                                                    new VerticalPosition(150f, LengthUnit.Millimeter, VerticalPositionAnchor.TopMargin),
                                                    new SautinSoft.Document.Drawing.Size(200, 200));

            AddPieChart(sectCharts, flP, productSales, true, "£", true, false);
        }