Exemple #1
0
 private static void CreateImage(object document, ImageText.ImageTextControl imgControl, bool isLinked, ref Paragraph header, bool border, bool isLast)
 {
     iText.Layout.Element.Image img = new iText.Layout.Element.Image(ImageDataFactory.Create((imgControl.Controls[0] as PictureBox).Image, System.Drawing.Color.White)).SetTextAlignment(TextAlignment.LEFT);
     if (isLinked)
     {
         img.SetAction(PdfAction.CreateURI((imgControl.Controls[0] as PictureBox).Name));
     }
     if (border)
     {
         img.SetBorder(new SolidBorder(ColorConstants.GRAY, 4)); img.SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER);
     }
     if (document.GetType() == typeof(Document))
     {
         (document as Document).Add(header);
         (document as Document).Add(img);
     }
     else
     {
         if (document.GetType() == typeof(Cell))
         {
             (document as Cell).Add(header);
             (document as Cell).Add(img);
         }
         else
         {
             if (document.GetType() == typeof(ListItem))
             {
                 (document as ListItem).Add(header);
                 (document as ListItem).Add(img);
             }
         }
     }
     header = new Paragraph();
     header.SetTextAlignment(TextAlignment.CENTER);
     for (int i = 1; i < imgControl.Controls.Count; i++)
     {
         Style style = new Style();
         if (imgControl.Controls[i].GetType() == typeof(Label))
         {
             Label label = imgControl.Controls[i] as Label;
             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();
             }
             if (label.Font.Underline)
             {
                 style.SetUnderline();
             }
             if (label.Font.Strikeout)
             {
                 style.SetLineThrough();
             }
             header.Add(new Text(label.Text).AddStyle(style));
         }
         else
         {
             if (imgControl.Controls[i].GetType() == typeof(Link.LinkControl))
             {
                 CreateLink(document, imgControl.Controls[i] as Link.LinkControl, header, border);
             }
         }
     }
     if (document.GetType() == typeof(Document))
     {
         (document as Document).Add(header);
     }
     else
     {
         if (document.GetType() == typeof(Cell))
         {
             (document as Cell).Add(header);
         }
         else
         {
             if (document.GetType() == typeof(ListItem))
             {
                 (document as ListItem).Add(header);
             }
         }
     }
     header = new Paragraph();
     if (border && !isLast)
     {
         header.SetBorderLeft(new SolidBorder(ColorConstants.GRAY, 4));
         header.SetPadding(30);
     }
 }
Exemple #2
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);
                }
            }
        }