private float AddDocumentLinkAnnotation(PdfPageBase page, float y)
        {
            PdfTrueTypeFont font   = new PdfTrueTypeFont(new Font("Arial", 12f));
            PdfStringFormat format = new PdfStringFormat();

            format.MeasureTrailingSpaces = true;
            String prompt = "Document Link: ";
            SizeF  size   = font.MeasureString(prompt);

            page.Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);
            float x = font.MeasureString(prompt, format).Width;

            PdfDestination dest = new PdfDestination(page);

            dest.Mode     = PdfDestinationMode.Location;
            dest.Location = new PointF(0, y);
            dest.Zoom     = 2f;

            String label = "Click me, Zoom 200%";

            size = font.MeasureString(label);
            RectangleF bounds = new RectangleF(x, y, size.Width, size.Height);

            page.Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);
            PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(bounds, dest);

            annotation.Color = Color.Blue;
            (page as PdfNewPage).Annotations.Add(annotation);
            y = bounds.Bottom;

            return(y);
        }
Beispiel #2
0
        /// <summary>
        /// Add content in table of content and return the layout result.
        /// </summary>
        PdfLayoutResult AddTableOfContents(PdfPage page, string text, RectangleF bounds, bool isTitle, int pageNo, float x, float y, PdfPage destPage)
        {
            //Set font style.
            PdfFontStyle style = isTitle ? PdfFontStyle.Bold : PdfFontStyle.Regular;
            //Create a font and draw the text to PDF page.
            PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 13, style);

            page.Graphics.DrawString(pageNo.ToString(), font, PdfBrushes.Black, new RectangleF(480, bounds.Top + 5, bounds.Width, bounds.Height));
            //Create a pdf destination for document link annotation.
            PdfDestination pdfDestination   = new PdfDestination(destPage, new PointF(x, y));
            RectangleF     annotationBounds = RectangleF.Empty;

            if (isTitle)
            {
                annotationBounds = new RectangleF(bounds.Left, bounds.Top - 45, bounds.Width, font.Height);
            }
            else
            {
                annotationBounds = new RectangleF(bounds.Left + 20, bounds.Top - 45, bounds.Width - 20, font.Height);
            }
            //Create document link annotation with bounds.
            PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(annotationBounds, pdfDestination);

            annotation.Border.Width = 0;
            //Add annotation to PDF page.
            page.Annotations.Add(annotation);

            //Measure the text size to draw in PDF page.
            string str   = text + ' ';
            float  width = isTitle ? font.MeasureString(text).Width + 20 : font.MeasureString(text).Width + 40;

            for (float i = width; i < 470;)
            {
                str = str + '.';
                i   = i + 3.6140000000000003F;
            }

            //Create text element and draw it to PDF page.
            PdfTextElement element = new PdfTextElement(str, font, PdfBrushes.Black);

            if (isTitle)
            {
                bounds = new RectangleF(bounds.Left, bounds.Top + 5, bounds.Width, bounds.Height);
            }
            else
            {
                bounds = new RectangleF(bounds.Left + 20, bounds.Top + 5, bounds.Width, bounds.Height);
            }

            return(element.Draw(page, bounds));
        }
Beispiel #3
0
        private static void AddDocumentLinkAnnotation(PdfDocument pdf, int AddPage, int DestinationPage, float y)
        {
            //Define a font
            PdfTrueTypeFont font = new PdfTrueTypeFont(new Font("Arial", 12f));

            //Set the string format
            PdfStringFormat format = new PdfStringFormat(PdfTextAlignment.Left);

            //Text string
            String prompt = "Local document Link: ";

            //Draw text string on page that
            pdf.Pages[AddPage].Canvas.DrawString(prompt, font, PdfBrushes.DodgerBlue, 0, y);

            //Use MeasureString to get the width of string
            float x = font.MeasureString(prompt, format).Width;

            //Create a PdfDestination with specific page
            PdfDestination dest = new PdfDestination(pdf.Pages[DestinationPage]);

            //Set the location of destination
            dest.Location = new PointF(0, y);

            //Set 50% zoom factor
            dest.Zoom = 0.5f;

            //Label string
            String label = "Click here to link the second page.";

            //Use MeasureString to get the SizeF of string
            SizeF size = font.MeasureString(label);

            //Create a rectangle
            RectangleF bounds = new RectangleF(x, y, size.Width, size.Height);

            //Draw label string
            pdf.Pages[AddPage].Canvas.DrawString(label, font, PdfBrushes.OrangeRed, x, y);

            //Create PdfDocumentLinkAnnotation on the rectangle and link to the destination
            PdfDocumentLinkAnnotation annotation = new PdfDocumentLinkAnnotation(bounds, dest);

            //Set color for annotation
            annotation.Color = Color.Blue;

            //Add annotation to the page
            (pdf.Pages[AddPage] as PdfNewPage).Annotations.Add(annotation);
        }
Beispiel #4
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);
                 }
             }
         }
     }
 }
Beispiel #5
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);
                         }
                     }
                 }
             }
         }
     }
 }