Пример #1
0
        private static void CreateLink(object document, Link.LinkControl control, Paragraph header, bool border)
        {
            for (int k = 0; k < control.Controls.Count; k++)
            {
                if (control.Controls[k].GetType() == typeof(LinkLabel))
                {
                    Style     style = new Style();
                    LinkLabel label = control.Controls[k] as LinkLabel;
                    iText.Kernel.Geom.Rectangle rect       = new iText.Kernel.Geom.Rectangle(0, 0);
                    PdfLinkAnnotation           annotation = new PdfLinkAnnotation(rect);
                    PdfAction action = PdfAction.CreateURI(label.Links[0].LinkData.ToString());
                    annotation.SetAction(action);
                    annotation.SetContents(label.ContextMenuStrip.Text);
                    iText.Layout.Element.Link link = new iText.Layout.Element.Link(label.Text, annotation);
                    style.SetFont(PdfFontFactory.CreateFont("C:\\Windows\\Fonts\\times.ttf", "Cp1251", true));
                    style.SetFontSize(label.Font.Size);
                    if (label.Font.Bold)
                    {
                        style.SetBold();
                    }
                    if (label.Font.Italic)
                    {
                        style.SetItalic();
                    }
                    style.SetUnderline();
                    if (label.Font.Strikeout)
                    {
                        style.SetLineThrough();
                    }
                    style.SetFontColor(ColorConstants.BLUE);
                    header.Add(link.AddStyle(style));
                    #region Анотация, которую я так и не смог сделать

                    /*
                     * // Creating a PdfTextMarkupAnnotation object
                     * rect = new Rectangle(35, 785, 0, 0);
                     * float[] floatArray = new float[] { 35, 785, 45, 785, 35, 795, 45, 795 };
                     * PdfAnnotation Annotation = PdfTextMarkupAnnotation.CreateUnderline(rect, floatArray);
                     *
                     * // Setting color to the annotation
                     * Annotation.SetColor(ColorConstants.BLUE);
                     *
                     * // Setting title to the annotation
                     * Annotation.SetTitle(new PdfString(label.ContextMenuStrip.Text));
                     *
                     * // Setting contents to the annotation
                     * Annotation.SetContents(" ");
                     *
                     * // Creating a new Pdfpage
                     * PdfPage pdfPage = pdf.AddNewPage();
                     *
                     * // Adding annotation to a page in a PDF
                     * pdfPage.AddAnnotation(Annotation);
                     */
                    #endregion
                }
                else
                {
                    ImageText.ImageTextControl picture = (control.Controls[k] as ImageText.ImageTextControl);
                    CreateImage(document, picture, true, ref header, border, k + 1 == control.Controls.Count);
                }
            }
        }