示例#1
0
 private void method_22(List <BookmarkLevel> A_0, PdfBookmark A_1)
 {
     if (A_0.Count > 0)
     {
         if (A_1 == null)
         {
             A_1 = this.pdfNewDocument_0.get_Bookmarks().Add(this.method_1().WordBookmarksTitle);
             A_1.set_Color((PdfRGBColor)this.method_1().WordBookmarksColor);
             A_1.set_DisplayStyle(this.method_24(this.method_1().WordBookmarksTextStyle));
         }
         for (int i = 0; i < A_0.Count; i++)
         {
             BookmarkLevel level = A_0[i];
             if ((this.pdfNewDocument_0.get_Pages().get_Count() >= level.TargetPageNumber) && (level.TargetPageNumber != 0))
             {
                 PdfPageBase base2 = this.pdfNewDocument_0.get_Pages().get_Item(level.TargetPageNumber - 1);
                 RectangleF  ef    = new RectangleF();
                 PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(ef);
                 PdfBookmark bookmark = null;
                 annotation.set_Border(new PdfAnnotationBorder(0f));
                 PdfDestination destination = new PdfDestination(base2, level.TargetBounds.Location);
                 bookmark = A_1.Add(level.Name);
                 bookmark.set_Color((!(level.Color == Color.SaddleBrown) || !(this.method_1().WordBookmarksColor != Color.SaddleBrown)) ? ((PdfRGBColor)level.Color) : ((PdfRGBColor)this.method_1().WordBookmarksColor));
                 bookmark.set_DisplayStyle(((level.Style != BookmarkTextStyle.Bold) || (this.method_1().WordBookmarksTextStyle == BookmarkTextStyle.Bold)) ? this.method_24(level.Style) : this.method_24(this.method_1().WordBookmarksTextStyle));
                 annotation.set_Destination(destination);
                 bookmark.set_Action(new PdfGoToAction(annotation.get_Destination()));
                 if (base2 is PdfNewPage)
                 {
                     (base2 as PdfNewPage).get_Annotations().Add(annotation);
                 }
                 else
                 {
                     (base2 as PdfPageWidget).get_AnnotationsWidget().Add(annotation);
                 }
                 if ((level.ChildObjects.Count > 0) && (bookmark != null))
                 {
                     this.method_22(level.ChildObjects, bookmark);
                 }
             }
         }
     }
 }
示例#2
0
        /// <summary>
        /// Add a bookmark to bookmark collection.
        /// </summary>
        PdfBookmark AddBookmark(PdfPage page, string text, PointF point, PdfDocument doc, PdfBookmark bookmark, PdfColor color)
        {
            PdfBookmark book;

            if (doc != null)
            {
                //Create and add a bookmark.
                book = doc.Bookmarks.Add(text);
                //Set destination for bookmark.
                book.Destination = new PdfDestination(page, point);
            }
            else
            {
                //Create and add a bookmark.
                book = bookmark.Add(text);
                //Set destination for bookmark.
                book.Destination = new PdfDestination(page, point);
            }

            book.Color = color;
            return(book);
        }
        private void button1_Click(object sender, EventArgs e)
        {
            //Create a pdf document.
            PdfDocument doc = new PdfDocument();

            //margin
            PdfUnitConvertor unitCvtr = new PdfUnitConvertor();
            PdfMargins       margin   = new PdfMargins();

            margin.Top    = unitCvtr.ConvertUnits(2.54f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Bottom = margin.Top;
            margin.Left   = unitCvtr.ConvertUnits(3.17f, PdfGraphicsUnit.Centimeter, PdfGraphicsUnit.Point);
            margin.Right  = margin.Left;

            //create section
            PdfSection section = doc.Sections.Add();

            section.PageSettings.Size    = PdfPageSize.A4;
            section.PageSettings.Margins = margin;

            // Create one page
            PdfPageBase page = section.Pages.Add();

            float y = 10;

            //title
            PdfBrush        brush1  = PdfBrushes.Black;
            PdfTrueTypeFont font1   = new PdfTrueTypeFont(new Font("Arial", 16f, FontStyle.Bold));
            PdfStringFormat format1 = new PdfStringFormat(PdfTextAlignment.Center);

            page.Canvas.DrawString("Sales Report", font1, brush1, page.Canvas.ClientSize.Width / 2, y, format1);
            y = y + font1.MeasureString("Sales Report", format1).Height;
            y = y + 5;

            PdfTrueTypeFont font2 = new PdfTrueTypeFont(new Font("Arial", 11f, FontStyle.Bold));
            PdfTrueTypeFont font3 = new PdfTrueTypeFont(new Font("Arial", 10f, FontStyle.Bold));

            using (OleDbConnection conn = new OleDbConnection())
            {
                conn.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\..\..\..\..\..\Data\demo.mdb";
                conn.Open();

                OleDbCommand partQueryCommand      = PreparePartQueryCommand(conn);
                OleDbCommand orderItemQueryCommand = PrepareOrderItemQueryCommand(conn);

                DataTable vendors = GetVendors(conn);
                for (int i = 0; i < vendors.Rows.Count; i++)
                {
                    if (i > 0)
                    {
                        //next page
                        page = section.Pages.Add();
                        y    = 0;
                    }
                    //draw vendor
                    String          vendorTitle            = String.Format("{0}. {1}", i + 1, vendors.Rows[i].ItemArray[1]);
                    PdfLayoutResult drawVendorLayoutResult = DrawVendor(page, vendors, i, vendorTitle, y);

                    //add vendor bookmark
                    PdfDestination vendorBookmarkDest = new PdfDestination(page, new PointF(0, y));
                    PdfBookmark    vendorBookmark     = doc.Bookmarks.Add(vendorTitle);
                    vendorBookmark.Color        = Color.SaddleBrown;
                    vendorBookmark.DisplayStyle = PdfTextStyle.Bold;
                    vendorBookmark.Action       = new PdfGoToAction(vendorBookmarkDest);

                    y    = drawVendorLayoutResult.Bounds.Bottom + 5;
                    page = drawVendorLayoutResult.Page;

                    //get parts of vendor
                    DataTable parts = GetParts(partQueryCommand, (double)vendors.Rows[i].ItemArray[0]);
                    for (int j = 0; j < parts.Rows.Count; j++)
                    {
                        if (j > 0)
                        {
                            //next page
                            page = section.Pages.Add();
                            y    = 0;
                        }
                        //draw part
                        String          partTitle            = String.Format("{0}.{1}. {2}", i + 1, j + 1, parts.Rows[j].ItemArray[1]);
                        PdfLayoutResult drawPartLayoutResult = DrawPart(page, parts, j, partTitle, y);

                        //add part bookmark
                        PdfDestination partBookmarkDest = new PdfDestination(page, new PointF(0, y));
                        PdfBookmark    partBookmark     = vendorBookmark.Add(partTitle);
                        partBookmark.Color        = Color.Coral;
                        partBookmark.DisplayStyle = PdfTextStyle.Italic;
                        partBookmark.Action       = new PdfGoToAction(partBookmarkDest);

                        y    = drawPartLayoutResult.Bounds.Bottom + 5;
                        page = drawPartLayoutResult.Page;

                        //get order items
                        String    orderItemsTitle = String.Format("{0} - Order Items", parts.Rows[j].ItemArray[1]);
                        DataTable orderItems      = GetOrderItems(orderItemQueryCommand, (double)parts.Rows[j].ItemArray[0]);
                        DrawOrderItems(page, orderItems, orderItemsTitle, y);
                    }
                }
            }

            //Save pdf file.
            doc.SaveToFile("Bookmark.pdf");
            doc.Close();

            //Launching the Pdf file.
            PDFDocumentViewer("Bookmark.pdf");
        }
示例#4
0
 private void method_20(List <Dictionary <string, Class310> > A_0, Dictionary <string, PdfBookmark> A_1, bool A_2)
 {
     for (int i = 0; i < A_0.Count; i++)
     {
         foreach (KeyValuePair <string, Class310> pair in A_0[i])
         {
             Class310 class2 = pair.Value;
             if (class2.method_16() == A_2)
             {
                 int index = this.pdfNewDocument_0.get_Pages().IndexOf(this.pdfPageBase_0);
                 if (class2.method_6() == (index + 1))
                 {
                     if (pair.Value.method_12() == 1)
                     {
                         A_1.Clear();
                     }
                     if (!pair.Key.Equals(string.Empty))
                     {
                         float height = this.method_0()[index].PageSize.Height;
                         PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(class2.method_0());
                         annotation.set_Border(new PdfAnnotationBorder(0f));
                         if ((this.pdfNewDocument_0.get_Pages().get_Count() >= class2.method_4()) && (class2.method_4() != 0))
                         {
                             PdfDestination destination = new PdfDestination(this.pdfNewDocument_0.get_Pages().get_Item(class2.method_4() - 1), class2.method_2().Location);
                             string[]       strArray    = class2.method_8().Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                             if ((strArray.Length > 2) && (strArray[1] == strArray[2]))
                             {
                                 PdfBookmark bookmark = this.pdfNewDocument_0.get_Bookmarks().Add(class2.method_10());
                                 bookmark.set_Color((PdfRGBColor)Color.SaddleBrown);
                                 bookmark.set_DisplayStyle(2);
                                 annotation.set_Destination(destination);
                                 bookmark.set_Action(new PdfGoToAction(annotation.get_Destination()));
                             }
                             else if (pair.Value.method_12() == 0)
                             {
                                 annotation.set_Destination(destination);
                             }
                             else if (pair.Value.method_12() == 1)
                             {
                                 PdfBookmark bookmark3 = this.pdfNewDocument_0.get_Bookmarks().Add(class2.method_10());
                                 bookmark3.set_Color((PdfRGBColor)Color.SaddleBrown);
                                 bookmark3.set_DisplayStyle(2);
                                 annotation.set_Destination(destination);
                                 bookmark3.set_Action(new PdfGoToAction(annotation.get_Destination()));
                                 A_1.Add(pair.Value.method_12().ToString(), bookmark3);
                             }
                             else
                             {
                                 PdfBookmark bookmark4 = null;
                                 A_1.TryGetValue((pair.Value.method_12() - 1).ToString(), out bookmark4);
                                 if (bookmark4 != null)
                                 {
                                     PdfBookmark bookmark2 = bookmark4.Add(class2.method_10());
                                     bookmark2.set_Color((PdfRGBColor)Color.SaddleBrown);
                                     bookmark2.set_DisplayStyle(2);
                                     annotation.set_Destination(destination);
                                     bookmark2.set_Action(new PdfGoToAction(annotation.get_Destination()));
                                     if (A_1.ContainsKey(pair.Value.method_12().ToString()))
                                     {
                                         A_1.Remove(pair.Value.method_12().ToString());
                                     }
                                     A_1.Add(pair.Value.method_12().ToString(), bookmark2);
                                 }
                             }
                         }
                         if (this.pdfPageBase_0 is PdfNewPage)
                         {
                             (this.pdfPageBase_0 as PdfNewPage).get_Annotations().Add(annotation);
                         }
                         else
                         {
                             (this.pdfPageBase_0 as PdfPageWidget).get_AnnotationsWidget().Add(annotation);
                         }
                     }
                 }
             }
         }
     }
 }