private PdfPTable GenerateTable(TableElement el)
        {
            var table = new PdfPTable(el.ColumnCount);
            if (el.Width > 0)
            {
                table.TotalWidth = el.Width;
                table.LockedWidth = true;
                table.SetWidths(el.ColumnWidths);
            }

            foreach (var row in el.Rows)
            {
                foreach (var c in row.Cells)
                {
                    if (c.NestedTable == null)
                    {
                        var cell = new PdfPCell();
                        var fontSize = c.FontSize > 0 ? c.FontSize : el.FontSize;
                        var f = new iTextSharp.text.Font(c.FontBold ? fontBold : font, fontSize);
                        cell.Phrase = new Phrase(c.Text, f);
                        //cell.Border = el.Border;
                        cell.Padding = c.Padding > 0 ? c.Padding : el.CellPadding;
                        cell.BorderWidth = el.BorderWidth;
                        cell.Colspan = c.ColumnSpan;
                        cell.Rowspan = c.RowSpan;
                        cell.HorizontalAlignment = c.Alignment;
                        cell.VerticalAlignment = PdfPCell.ALIGN_MIDDLE;
                        if (c.Height > 0)
                        {
                            cell.MinimumHeight = c.Height;
                            cell.FixedHeight = c.Height;
                        }
                        if (c.BackgroundColor != Color.Empty)
                            cell.BackgroundColor = new BaseColor(c.BackgroundColor);
                        table.AddCell(cell);
                    }
                    else
                    {
                        var nested = GenerateTable(c.NestedTable);
                        PdfPCell nesthousing = new PdfPCell(nested);
                        nesthousing.Padding = 0f;
                        nesthousing.Border = 0;
                        table.AddCell(nesthousing);
                    }
                }
            }
            return table;
        }
 private void RenderTableElement(TableElement el, PdfContentByte dc)
 {
     var table = GenerateTable(el);
     table.WriteSelectedRows(0, table.Rows.Count, TranslateLeft(el), TranslateTop(el), dc);
     el.Height = table.CalculateHeights();
 }
Exemple #3
0
 public TableCell(TableElement nestedTable)
     : this()
 {
     NestedTable = nestedTable;
 }