Ejemplo n.º 1
0
        /// <summary>
        /// Renderizza un elemento immagine in una cella iTextSharp.text.
        /// </summary>
        /// <param name="ImgElement">
        /// Elemento immagine. NOTA: il percorso dev'essere ASSOLUTO, ad esempio C:\img\img.gif
        /// </param>
        /// <returns>
        /// iTextSharp.text.Cell con i contenuti opportuni
        /// </returns>
        private static iTextSharp.text.Cell RenderElement(DocTemplateVers.Domain.DTO.ServiceExport.DTO_ElementImage ImgElement, float MaxWidth)
        {
            iTextSharp.text.Cell cell = new iTextSharp.text.Cell();
            cell.Border = 0;
            RtfHelper.SetAlignment(ref cell, ImgElement.Alignment);
            //cell.Width = MaxWidth;

            iTextSharp.text.Image img;
            try
            {
                img = iTextSharp.text.Image.GetInstance(ImgElement.Path);


                if (ImgElement.Width > 0 && ImgElement.Height > 0)
                {
                    img.ScaleAbsolute(ImgElement.Width, ImgElement.Height);
                }
                else if (ImgElement.Width > 0)
                {
                    img.ScaleAbsoluteWidth(ImgElement.Width);
                }
                else if (ImgElement.Height > 0)
                {
                    img.ScaleAbsoluteHeight(ImgElement.Height);
                }

                if (img.Width > MaxWidth)
                {
                    img.ScaleAbsoluteWidth(MaxWidth);
                }

                cell.AddElement(img);
            }
            catch (Exception ex)
            {
                //cell = null;
            }

            return(cell);

            //return new iTextSharp.text.Cell(new iTextSharp.text.Paragraph("NOT IMPLEMENT!"));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Aggiunge nel flusso doc corrente gli elementi convertiti da una stringa HTML...
        /// </summary>
        /// <param name="doc">Il document corrente a cui aggiungere gli elementi</param>
        /// <param name="html">Il codice HTML da aggiungere</param>
        /// <remarks>
        ///     1. TESTARE!!!
        ///     2. Generalizzare. Questa funzione lavora su Document,
        ///     altre invece lavorano su
        /// </remarks>
        protected static void AddHTMLcontent(iTS.Document doc, string html)
        {
            System.Collections.ArrayList AL_Content = iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new System.IO.StringReader(RtfHelper.HtmlCheckRtf(html)), RtfHelper.GetStyles());

            for (int j = 0; j < AL_Content.Count; j++)
            {
                //Eventuali funzioni per la correzine ad esempio delle Liste...
                doc.Add(CheckconvertedElement((iTextSharp.text.IElement)AL_Content[j]));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Renderizza un elemento testuale in una cella iTextSharp.text.
        /// </summary>
        /// <param name="TxtElement">
        /// Elemento testuale
        /// </param>
        /// <returns>
        /// iTextSharp.text.Cell con i contenuti opportuni
        /// </returns>
        private static iTextSharp.text.Cell RenderElement(DocTemplateVers.Domain.DTO.ServiceExport.DTO_ElementText TxtElement, float MaxWidth)
        {
            iTextSharp.text.Cell cell;        // = new iTextSharp5.text.Cell();
            if (TxtElement.IsHTML)
            {
                cell = HtmlToCell(TxtElement.Text);
                //HtmlCheck(TxtElement.Text);

                //                   cell = new iTextSharp.text.Cell();

                //                   System.Collections.ArrayList AL_Content =
                //iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(
                //new System.IO.StringReader(RtfHelper.HtmlCheckRtf(TxtElement.Text)),
                //RtfHelper.GetStyles());

                //                   for (int j = 0; j < AL_Content.Count; j++)
                //                   {
                //                       cell.AddElement(CheckconvertedElement((iTextSharp.text.IElement)AL_Content[j]));
                //                   }
            }
            else
            {
                cell = new iTextSharp.text.Cell(
                    new iTextSharp.text.Paragraph(TxtElement.Text)
                    );



                //switch (TxtElement.Alignment)
                //{
                //    case Helpers.Export.ElementAlignment.BottomCenter:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER; // = iTextSharp5.text.Cell.ALIGN_CENTER;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_BOTTOM;
                //        break;
                //    case Helpers.Export.ElementAlignment.BottomLeft:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_BOTTOM;
                //        break;
                //    case Helpers.Export.ElementAlignment.BottomRight:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_BOTTOM;
                //        break;

                //    case Helpers.Export.ElementAlignment.MiddleCenter:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                //        break;
                //    case Helpers.Export.ElementAlignment.MiddleLeft:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                //        break;
                //    case Helpers.Export.ElementAlignment.MiddleRight:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_MIDDLE;
                //        break;

                //    case Helpers.Export.ElementAlignment.TopCenter:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_CENTER;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
                //        break;
                //    case Helpers.Export.ElementAlignment.TopLeft:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
                //        break;
                //    case Helpers.Export.ElementAlignment.TopRight:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
                //        break;

                //    default:
                //        cell.HorizontalAlignment = iTextSharp.text.Element.ALIGN_LEFT;
                //        cell.VerticalAlignment = iTextSharp.text.Element.ALIGN_TOP;
                //        break;
                //}
            }

            if (cell != null)
            {
                RtfHelper.SetAlignment(ref cell, TxtElement.Alignment);
                cell.Border = 0;
            }


            return(cell);
        }