iTextSharp.text.pdf.ColumnText.AddElement C# (CSharp) Метод

AddElement() публичный Метод

public AddElement ( IElement element ) : void
element IElement
Результат void
    public void AddElement(IElement element) {
        if (element == null)
            return;
        if (element is Image) {
            Image img = (Image)element;
            PdfPTable t = new PdfPTable(1);
            float w = img.WidthPercentage;
            if (w == 0) {
                t.TotalWidth = img.ScaledWidth;
                t.LockedWidth = true;
            }
            else
                t.WidthPercentage = w;
            t.SpacingAfter = img.SpacingAfter;
            t.SpacingBefore = img.SpacingBefore;
            switch (img.Alignment) {
                case Image.LEFT_ALIGN:
                    t.HorizontalAlignment = Element.ALIGN_LEFT;
                    break;
                case Image.RIGHT_ALIGN:
                    t.HorizontalAlignment = Element.ALIGN_RIGHT;
                    break;
                default:
                    t.HorizontalAlignment = Element.ALIGN_CENTER;
                    break;
            }
            PdfPCell c = new PdfPCell(img, true);
            c.Padding = 0;
            c.Border = img.Border;
            c.BorderColor = img.BorderColor;
            c.BorderWidth = img.BorderWidth;
            c.BackgroundColor = img.BackgroundColor;
            t.AddCell(c);
            element = t;
        }
        if (element.Type == Element.CHUNK) {
            element = new Paragraph((Chunk)element);
        }
        else if (element.Type == Element.PHRASE) {
            element = new Paragraph((Phrase)element);
        } else if (element.Type == Element.PTABLE) {
            element = new PdfPTable((PdfPTable)element);
        }
        if (element.Type != Element.PARAGRAPH && element.Type != Element.LIST && element.Type != Element.PTABLE && element.Type != Element.YMARK && element.Type != Element.DIV)
            throw new ArgumentException(MessageLocalization.GetComposedMessage("element.not.allowed"));
        if (!composite) {
            composite = true;
            compositeElements = new List<IElement>();
            bidiLine = null;
            waitPhrase = null;
        }
        if (element.Type == Element.PARAGRAPH) {
            Paragraph p = (Paragraph)element;
            IList<IElement> paragraphElements = p.breakUp();
            foreach (IElement paragraphElement in paragraphElements) {
                compositeElements.Add(paragraphElement);    
            }
            return;
        }
        compositeElements.Add(element);
    }

Usage Example

Пример #1
0
 /** Constructs a <CODE>PdfPCell</CODE> with a <CODE>PdfPtable</CODE>.
  * This constructor allows nested tables.
  *
  * @param table The <CODE>PdfPTable</CODE>
  * @param style  The style to apply to the cell (you could use getDefaultCell())
  * @since 2.1.0
  */
 public PdfPCell(PdfPTable table, PdfPCell style) : base(0, 0, 0, 0)
 {
     borderWidth = 0.5f;
     border      = BOX;
     column.SetLeading(0, 1);
     this.table            = table;
     table.WidthPercentage = 100;
     table.ExtendLastRow   = true;
     column.AddElement(table);
     if (style != null)
     {
         CloneNonPositionParameters(style);
         verticalAlignment = style.verticalAlignment;
         paddingLeft       = style.paddingLeft;
         paddingRight      = style.paddingRight;
         paddingTop        = style.paddingTop;
         paddingBottom     = style.paddingBottom;
         colspan           = style.colspan;
         rowspan           = style.rowspan;
         cellEvent         = style.cellEvent;
         useDescender      = style.useDescender;
         useBorderPadding  = style.useBorderPadding;
         rotation          = style.rotation;
     }
     else
     {
         Padding = 0;
     }
 }
All Usage Examples Of iTextSharp.text.pdf.ColumnText::AddElement