/// <summary> /// Adds content to this object. /// @throws BadElementException /// </summary> /// <param name="element"></param> public void AddElement(SimpleCell element) { if (!element.Cellgroup) { throw new BadElementException("You can't add cells to a table directly, add them to a row first."); } _content.Add(element); }
/** * Adds content to this object. * @param element * @throws BadElementException */ public void AddElement(SimpleCell element) { if (!element.Cellgroup) { throw new BadElementException(MessageLocalization.GetComposedMessage("you.can.t.add.cells.to.a.table.directly.add.them.to.a.row.first")); } content.Add(element); }
/** * @param rectangle * @param spacing * @return a rectangle */ public static SimpleCell GetDimensionlessInstance(Rectangle rectangle, float spacing) { SimpleCell cell = new SimpleCell(CELL); cell.CloneNonPositionParameters(rectangle); cell.Spacing = spacing * 2; return(cell); }
/** * Creates a Cell with these attributes. * @param rowAttributes * @return a cell based on these attributes. * @throws BadElementException */ public Cell CreateCell(SimpleCell rowAttributes) { Cell cell = new Cell(); cell.CloneNonPositionParameters(rowAttributes); cell.SoftCloneNonPositionParameters(this); cell.Colspan = colspan; cell.HorizontalAlignment = horizontalAlignment; cell.VerticalAlignment = verticalAlignment; cell.UseAscender = useAscender; cell.UseBorderPadding = useBorderPadding; cell.UseDescender = useDescender; foreach (IElement element in content) { cell.AddElement(element); } return(cell); }
/** * Creates a PdfPCell with these attributes. * @param rowAttributes * @return a PdfPCell based on these attributes. */ public PdfPCell CreatePdfPCell(SimpleCell rowAttributes) { PdfPCell cell = new PdfPCell(); cell.Border = NO_BORDER; SimpleCell tmp = new SimpleCell(CELL); tmp.Spacing_left = spacing_left; tmp.Spacing_right = spacing_right; tmp.Spacing_top = spacing_top; tmp.Spacing_bottom = spacing_bottom; tmp.CloneNonPositionParameters(rowAttributes); tmp.SoftCloneNonPositionParameters(this); cell.CellEvent = tmp; cell.HorizontalAlignment = rowAttributes.horizontalAlignment; cell.VerticalAlignment = rowAttributes.verticalAlignment; cell.UseAscender = rowAttributes.useAscender; cell.UseBorderPadding = rowAttributes.useBorderPadding; cell.UseDescender = rowAttributes.useDescender; cell.Colspan = colspan; if (horizontalAlignment != Element.ALIGN_UNDEFINED) cell.HorizontalAlignment = horizontalAlignment; if (verticalAlignment != Element.ALIGN_UNDEFINED) cell.VerticalAlignment = verticalAlignment; if (useAscender) cell.UseAscender = useAscender; if (useBorderPadding) cell.UseBorderPadding = useBorderPadding; if (useDescender) cell.UseDescender = useDescender; float p; float sp_left = spacing_left; if (float.IsNaN(sp_left)) sp_left = 0f; float sp_right = spacing_right; if (float.IsNaN(sp_right)) sp_right = 0f; float sp_top = spacing_top; if (float.IsNaN(sp_top)) sp_top = 0f; float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) sp_bottom = 0f; p = padding_left; if (float.IsNaN(p)) p = 0f; cell.PaddingLeft = p + sp_left; p = padding_right; if (float.IsNaN(p)) p = 0f; cell.PaddingRight = p + sp_right; p = padding_top; if (float.IsNaN(p)) p = 0f; cell.PaddingTop = p + sp_top; p = padding_bottom; if (float.IsNaN(p)) p = 0f; cell.PaddingBottom = p + sp_bottom; foreach (IElement element in content) { cell.AddElement(element); } return cell; }
/** * Creates a Cell with these attributes. * @param rowAttributes * @return a cell based on these attributes. * @throws BadElementException */ public Cell CreateCell(SimpleCell rowAttributes) { Cell cell = new Cell(); cell.CloneNonPositionParameters(rowAttributes); cell.SoftCloneNonPositionParameters(this); cell.Colspan = colspan; cell.HorizontalAlignment = horizontalAlignment; cell.VerticalAlignment = verticalAlignment; cell.UseAscender = useAscender; cell.UseBorderPadding = useBorderPadding; cell.UseDescender = useDescender; foreach (IElement element in content) { cell.AddElement(element); } return cell; }
/** * Creates a PdfPCell with these attributes. * @param rowAttributes * @return a PdfPCell based on these attributes. */ public PdfPCell CreatePdfPCell(SimpleCell rowAttributes) { PdfPCell cell = new PdfPCell(); cell.Border = NO_BORDER; SimpleCell tmp = new SimpleCell(CELL); tmp.Spacing_left = spacing_left; tmp.Spacing_right = spacing_right; tmp.Spacing_top = spacing_top; tmp.Spacing_bottom = spacing_bottom; tmp.CloneNonPositionParameters(rowAttributes); tmp.SoftCloneNonPositionParameters(this); cell.CellEvent = tmp; cell.HorizontalAlignment = rowAttributes.horizontalAlignment; cell.VerticalAlignment = rowAttributes.verticalAlignment; cell.UseAscender = rowAttributes.useAscender; cell.UseBorderPadding = rowAttributes.useBorderPadding; cell.UseDescender = rowAttributes.useDescender; cell.Colspan = colspan; if (horizontalAlignment != Element.ALIGN_UNDEFINED) { cell.HorizontalAlignment = horizontalAlignment; } if (verticalAlignment != Element.ALIGN_UNDEFINED) { cell.VerticalAlignment = verticalAlignment; } if (useAscender) { cell.UseAscender = useAscender; } if (useBorderPadding) { cell.UseBorderPadding = useBorderPadding; } if (useDescender) { cell.UseDescender = useDescender; } float p; float sp_left = spacing_left; if (float.IsNaN(sp_left)) { sp_left = 0f; } float sp_right = spacing_right; if (float.IsNaN(sp_right)) { sp_right = 0f; } float sp_top = spacing_top; if (float.IsNaN(sp_top)) { sp_top = 0f; } float sp_bottom = spacing_bottom; if (float.IsNaN(sp_bottom)) { sp_bottom = 0f; } p = padding_left; if (float.IsNaN(p)) { p = 0f; } cell.PaddingLeft = p + sp_left; p = padding_right; if (float.IsNaN(p)) { p = 0f; } cell.PaddingRight = p + sp_right; p = padding_top; if (float.IsNaN(p)) { p = 0f; } cell.PaddingTop = p + sp_top; p = padding_bottom; if (float.IsNaN(p)) { p = 0f; } cell.PaddingBottom = p + sp_bottom; foreach (IElement element in content) { cell.AddElement(element); } return(cell); }
/** * Creates a Table object based on this TableAttributes object. * @return a com.lowagie.text.Table object * @throws BadElementException */ public Table CreateTable() { if (content.Count == 0) { throw new BadElementException(MessageLocalization.GetComposedMessage("trying.to.create.a.table.without.rows")); } SimpleCell rowx = (SimpleCell)content[0]; int columns = 0; foreach (SimpleCell cell in rowx.Content) { columns += cell.Colspan; } float[] widths = new float[columns]; float[] widthpercentages = new float[columns]; Table table = new Table(columns); table.Alignment = alignment; table.Spacing = cellspacing; table.Padding = cellpadding; table.CloneNonPositionParameters(this); int pos; foreach (SimpleCell row in content) { pos = 0; foreach (SimpleCell cell in row.Content) { table.AddCell(cell.CreateCell(row)); if (cell.Colspan == 1) { if (cell.Width > 0) { widths[pos] = cell.Width; } if (cell.Widthpercentage > 0) { widthpercentages[pos] = cell.Widthpercentage; } } pos += cell.Colspan; } } float sumWidths = 0f; for (int i = 0; i < columns; i++) { if (widths[i] == 0) { sumWidths = 0; break; } sumWidths += widths[i]; } if (sumWidths > 0) { table.Width = sumWidths; table.Locked = true; table.Widths = widths; } else { for (int i = 0; i < columns; i++) { if (widthpercentages[i] == 0) { sumWidths = 0; break; } sumWidths += widthpercentages[i]; } if (sumWidths > 0) { table.Widths = widthpercentages; } } if (width > 0) { table.Width = width; table.Locked = true; } else if (widthpercentage > 0) { table.Width = widthpercentage; } return(table); }
/** * Creates a PdfPTable object based on this TableAttributes object. * @return a com.lowagie.text.pdf.PdfPTable object * @throws DocumentException */ public PdfPTable CreatePdfPTable() { if (content.Count == 0) { throw new BadElementException(MessageLocalization.GetComposedMessage("trying.to.create.a.table.without.rows")); } SimpleCell rowx = (SimpleCell)content[0]; int columns = 0; foreach (SimpleCell cell in rowx.Content) { columns += cell.Colspan; } float[] widths = new float[columns]; float[] widthpercentages = new float[columns]; PdfPTable table = new PdfPTable(columns); table.TableEvent = this; table.HorizontalAlignment = alignment; int pos; foreach (SimpleCell row in content) { pos = 0; foreach (SimpleCell cell in row.Content) { if (float.IsNaN(cell.Spacing_left)) { cell.Spacing_left = cellspacing / 2f; } if (float.IsNaN(cell.Spacing_right)) { cell.Spacing_right = cellspacing / 2f; } if (float.IsNaN(cell.Spacing_top)) { cell.Spacing_top = cellspacing / 2f; } if (float.IsNaN(cell.Spacing_bottom)) { cell.Spacing_bottom = cellspacing / 2f; } cell.Padding = cellpadding; table.AddCell(cell.CreatePdfPCell(row)); if (cell.Colspan == 1) { if (cell.Width > 0) { widths[pos] = cell.Width; } if (cell.Widthpercentage > 0) { widthpercentages[pos] = cell.Widthpercentage; } } pos += cell.Colspan; } } float sumWidths = 0f; for (int i = 0; i < columns; i++) { if (widths[i] == 0) { sumWidths = 0; break; } sumWidths += widths[i]; } if (sumWidths > 0) { table.TotalWidth = sumWidths; table.SetWidths(widths); } else { for (int i = 0; i < columns; i++) { if (widthpercentages[i] == 0) { sumWidths = 0; break; } sumWidths += widthpercentages[i]; } if (sumWidths > 0) { table.SetWidths(widthpercentages); } } if (width > 0) { table.TotalWidth = width; } if (widthpercentage > 0) { table.WidthPercentage = widthpercentage; } return(table); }
/// <summary> /// Creates a Table object based on this TableAttributes object. /// @throws BadElementException /// </summary> /// <returns>a com.lowagie.text.Table object</returns> public Table CreateTable() { if (_content.Count == 0) { throw new BadElementException("Trying to create a table without rows."); } SimpleCell rowx = (SimpleCell)_content[0]; int columns = 0; foreach (SimpleCell cell in rowx.Content) { columns += cell.Colspan; } float[] widths = new float[columns]; float[] widthpercentages = new float[columns]; Table table = new Table(columns); table.Alignment = _alignment; table.Spacing = _cellspacing; table.Padding = _cellpadding; table.CloneNonPositionParameters(this); int pos; foreach (SimpleCell row in _content) { pos = 0; foreach (SimpleCell cell in row.Content) { table.AddCell(cell.CreateCell(row)); if (cell.Colspan == 1) { if (cell.Width > 0) { widths[pos] = cell.Width; } if (cell.Widthpercentage > 0) { widthpercentages[pos] = cell.Widthpercentage; } } pos += cell.Colspan; } } float sumWidths = 0f; for (int i = 0; i < columns; i++) { if (widths[i].ApproxEquals(0)) { sumWidths = 0; break; } sumWidths += widths[i]; } if (sumWidths > 0) { table.Width = sumWidths; table.Locked = true; table.Widths = widths; } else { for (int i = 0; i < columns; i++) { if (widthpercentages[i].ApproxEquals(0)) { sumWidths = 0; break; } sumWidths += widthpercentages[i]; } if (sumWidths > 0) { table.Widths = widthpercentages; } } if (_width > 0) { table.Width = _width; table.Locked = true; } else if (_widthpercentage > 0) { table.Width = _widthpercentage; } return(table); }
/// <summary> /// Creates a PdfPTable object based on this TableAttributes object. /// @throws DocumentException /// </summary> /// <returns>a com.lowagie.text.pdf.PdfPTable object</returns> public PdfPTable CreatePdfPTable() { if (_content.Count == 0) { throw new BadElementException("Trying to create a table without rows."); } SimpleCell rowx = (SimpleCell)_content[0]; int columns = 0; foreach (SimpleCell cell in rowx.Content) { columns += cell.Colspan; } float[] widths = new float[columns]; float[] widthpercentages = new float[columns]; PdfPTable table = new PdfPTable(columns); table.TableEvent = this; table.HorizontalAlignment = _alignment; int pos; foreach (SimpleCell row in _content) { pos = 0; foreach (SimpleCell cell in row.Content) { if (float.IsNaN(cell.SpacingLeft)) { cell.SpacingLeft = _cellspacing / 2f; } if (float.IsNaN(cell.SpacingRight)) { cell.SpacingRight = _cellspacing / 2f; } if (float.IsNaN(cell.SpacingTop)) { cell.SpacingTop = _cellspacing / 2f; } if (float.IsNaN(cell.SpacingBottom)) { cell.SpacingBottom = _cellspacing / 2f; } cell.Padding = _cellpadding; table.AddCell(cell.CreatePdfPCell(row)); if (cell.Colspan == 1) { if (cell.Width > 0) { widths[pos] = cell.Width; } if (cell.Widthpercentage > 0) { widthpercentages[pos] = cell.Widthpercentage; } } pos += cell.Colspan; } } float sumWidths = 0f; for (int i = 0; i < columns; i++) { if (widths[i].ApproxEquals(0)) { sumWidths = 0; break; } sumWidths += widths[i]; } if (sumWidths > 0) { table.TotalWidth = sumWidths; table.SetWidths(widths); } else { for (int i = 0; i < columns; i++) { if (widthpercentages[i].ApproxEquals(0)) { sumWidths = 0; break; } sumWidths += widthpercentages[i]; } if (sumWidths > 0) { table.SetWidths(widthpercentages); } } if (_width > 0) { table.TotalWidth = _width; } if (_widthpercentage > 0) { table.WidthPercentage = _widthpercentage; } return(table); }
/** * Create a PdfPTable based on this Table object. * @return a PdfPTable object * @throws BadElementException */ public PdfPTable CreatePdfPTable() { if (!convert2pdfptable) { throw new BadElementException("No error, just an old style table"); } AutoFillEmptyCells = true; Complete(); PdfPTable pdfptable = new PdfPTable(widths); pdfptable.ElementComplete = complete; if (NotAddedYet) pdfptable.SkipFirstHeader = true; SimpleTable t_evt = new SimpleTable(); t_evt.CloneNonPositionParameters(this); t_evt.Cellspacing = cellspacing; pdfptable.TableEvent = t_evt; pdfptable.HeaderRows = lastHeaderRow + 1; pdfptable.SplitLate = cellsFitPage; pdfptable.KeepTogether = tableFitsPage; if (!float.IsNaN(offset)) { pdfptable.SpacingBefore = offset; } pdfptable.HorizontalAlignment = alignment; if (locked) { pdfptable.TotalWidth = width; pdfptable.LockedWidth = true; } else { pdfptable.WidthPercentage = width; } foreach (Row row in this) { IElement cell; PdfPCell pcell; for (int i = 0; i < row.Columns; i++) { if ((cell = (IElement)row.GetCell(i)) != null) { if (cell is Table) { pcell = new PdfPCell(((Table)cell).CreatePdfPTable()); } else if (cell is Cell) { pcell = ((Cell)cell).CreatePdfPCell(); pcell.Padding = cellpadding + cellspacing / 2f; SimpleCell c_evt = new SimpleCell(SimpleCell.CELL); c_evt.CloneNonPositionParameters((Cell)cell); c_evt.Spacing = cellspacing * 2f; pcell.CellEvent = c_evt; } else { pcell = new PdfPCell(); } pdfptable.AddCell(pcell); } } } return pdfptable; }
/** * Adds content to this object. * @param element * @throws BadElementException */ public void AddElement(SimpleCell element) { if (!element.Cellgroup) { throw new BadElementException("You can't add cells to a table directly, add them to a row first."); } content.Add(element); }
/** * @param rectangle * @param spacing * @return a rectangle */ public static SimpleCell GetDimensionlessInstance(Rectangle rectangle, float spacing) { SimpleCell cell = new SimpleCell(CELL); cell.CloneNonPositionParameters(rectangle); cell.Spacing = spacing * 2; return cell; }