Exemplo n.º 1
0
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "OutlineWithStyles.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                pdf.PageMode   = PdfPageMode.UseOutlines;
                pdf.PageLayout = PdfPageLayout.OneColumn;

                BuildTestOutline(pdf);

                PdfOutlineItem root = pdf.OutlineRoot;

                for (int i = 0; i < root.ChildCount; i++)
                {
                    PdfOutlineItem child = root.GetChild(i);

                    if (i % 2 == 0)
                    {
                        child.Bold = true;
                    }
                    else
                    {
                        child.Italic = true;
                    }

                    for (int j = 0; j < child.ChildCount; j++)
                    {
                        PdfOutlineItem childOfChild = child.GetChild(j);

                        if (j % 2 == 0)
                        {
                            childOfChild.Color = new PdfRgbColor(Color.DarkGreen);
                        }
                        else
                        {
                            childOfChild.Color = new PdfRgbColor(Color.BlueViolet);
                        }

                        childOfChild.Bold   = true;
                        childOfChild.Italic = true;
                    }
                }

                pdf.Save(pathToFile);
            }

            Process.Start(pathToFile);
        }
        public static void Main()
        {
            // NOTE:
            // When used in trial mode, the library imposes some restrictions.
            // Please visit http://bitmiracle.com/pdf-library/trial-restrictions.aspx
            // for more information.

            string pathToFile = "OutlineWithStyles.pdf";

            using (PdfDocument pdf = new PdfDocument())
            {
                pdf.PageMode   = PdfPageMode.UseOutlines;
                pdf.PageLayout = PdfPageLayout.OneColumn;

                BuildTestOutline(pdf);

                PdfOutlineItem root = pdf.OutlineRoot;

                for (int i = 0; i < root.ChildCount; i++)
                {
                    PdfOutlineItem child = root.GetChild(i);

                    if (i % 2 == 0)
                    {
                        child.Bold = true;
                    }
                    else
                    {
                        child.Italic = true;
                    }

                    for (int j = 0; j < child.ChildCount; j++)
                    {
                        PdfOutlineItem childOfChild = child.GetChild(j);

                        if (j % 2 == 0)
                        {
                            childOfChild.Color = new PdfRgbColor(0, 100, 0); // dark green
                        }
                        else
                        {
                            childOfChild.Color = new PdfRgbColor(138, 43, 226); // blue violet
                        }
                        childOfChild.Bold   = true;
                        childOfChild.Italic = true;
                    }
                }

                pdf.Save(pathToFile);
            }

            Console.WriteLine($"The output is located in {Environment.CurrentDirectory}");
        }