Table of Contents

Class Table

Namespace
iTextSharp.text
Assembly
iTextSharp.LGPLv2.Core.dll

A Table is a Rectangle that contains Cells, ordered in some kind of matrix.

public class Table : Rectangle, ILargeElement, IElement
Inheritance
Table
Implements
Inherited Members

Examples

// Remark: You MUST know the number of columns when constructing a Table. // The number of rows is not important. Table table = new Table(3); table.SetBorderWidth(1); table.SetBorderColor(new Color(0, 0, 255)); table.SetPadding(5); table.SetSpacing(5); Cell cell = new Cell("header"); cell.SetHeader(true); cell.SetColspan(3); table.AddCell(cell); table.EndHeaders(); cell = new Cell("example cell with colspan 1 and rowspan 2"); cell.SetRowspan(2); cell.SetBorderColor(new Color(255, 0, 0)); table.AddCell(cell); table.AddCell("1.1"); table.AddCell("2.1"); table.AddCell("1.2"); table.AddCell("2.2"); table.AddCell("cell test1"); cell = new Cell("big cell"); cell.SetRowspan(2); cell.SetColspan(2); table.AddCell(cell); table.AddCell("cell test2");

Remarks

Tables that span multiple pages are cut into different parts automatically. If you want a table header to be repeated on every page, you may not forget to mark the end of the header section by using the method EndHeaders(). The matrix of a table is not necessarily an m x n-matrix. It can contain holes or cells that are bigger than the unit. Believe me or not, but it took some serious thinking to make this as userfriendly as possible. I hope you wil find the result quite simple (I love simple solutions, especially for complex problems).

Constructors

Table(int)

constructors

public Table(int columns)

Parameters

columns int

The number of columns in the table

Table(int, int)

Constructs a Table with a certain number of columns and a certain number of Rows.

public Table(int columns, int rows)

Parameters

columns int

The number of columns in the table

rows int

The number of rows

Fields

autoFillEmptyCells

membervariables

protected bool autoFillEmptyCells

Field Value

bool

complete

Indicates if the PdfPTable is complete once added to the document. @since iText 2.0.8

protected bool complete

Field Value

bool

notAddedYet

Indicates if this is the first time the section was added. @since iText 2.0.8

protected bool notAddedYet

Field Value

bool

Properties

Alignment

implementation of the Element-methods

public int Alignment { get; set; }

Property Value

int

a value

AutoFillEmptyCells

Enables/disables automatic insertion of empty cells before table is rendered. (default = false)

public bool AutoFillEmptyCells { set; }

Property Value

bool

enable/disable autofill

Remarks

As some people may want to create a table, fill only a couple of the cells and don't bother with investigating which empty ones need to be added, this default behaviour may be very welcome. Disabling is recommended to increase speed. (empty cells should be added through extra code then)

Bottom

public override float Bottom { get; set; }

Property Value

float

Cellpadding

Get/set the cellpadding.

public float Cellpadding { get; set; }

Property Value

float

the cellpadding

CellsFitPage

Allows you to control when a page break occurs.

public bool CellsFitPage { get; set; }

Property Value

bool

a value

Remarks

When a cell doesn't fit a page, it is split in two parts. If you want to avoid this, you should set the cellsFitPage value to true.

Cellspacing

Get/set the cellspacing.

public float Cellspacing { get; set; }

Property Value

float

the cellspacing

Columns

Gets the number of columns.

public int Columns { get; }

Property Value

int

a value

Convert2Pdfptable

If set to true, iText will try to convert the Table to a PdfPTable.

public bool Convert2Pdfptable { get; set; }

Property Value

bool

DefaultCell

Sets the default layout of the Table to the provided Cell

public Cell DefaultCell { get; set; }

Property Value

Cell

DefaultCellBackgroundColor

Changes the backgroundcolor in the default layout of the Cells added with method AddCell(string content).

public BaseColor DefaultCellBackgroundColor { set; }

Property Value

BaseColor

the new color

DefaultCellBorder

Changes the border in the default layout of the Cells added with method AddCell(string content).

public int DefaultCellBorder { set; }

Property Value

int

the new border value

DefaultCellBorderColor

Changes the bordercolor in the default layout of the Cells added with method AddCell(string content).

public BaseColor DefaultCellBorderColor { set; }

Property Value

BaseColor

DefaultCellBorderWidth

Changes the width of the borders in the default layout of the Cells added with method AddCell(string content).

public float DefaultCellBorderWidth { set; }

Property Value

float

the new width

DefaultCellGrayFill

Changes the grayfill in the default layout of the Cells added with method AddCell(string content).

public float DefaultCellGrayFill { set; }

Property Value

float

the new value

DefaultColspan

Changes the colspan in the default layout of the Cells added with method AddCell(string content).

public int DefaultColspan { set; }

Property Value

int

the new colspan value

DefaultHorizontalAlignment

Changes the horizontalalignment in the default layout of the Cells added with method AddCell(string content).

public int DefaultHorizontalAlignment { set; }

Property Value

int

the new alignment value

DefaultLayout

Sets the default layout of the Table to the provided Cell

public Cell DefaultLayout { get; set; }

Property Value

Cell

DefaultRowspan

Changes the rowspan in the default layout of the Cells added with method AddCell(string content).

public int DefaultRowspan { set; }

Property Value

int

the new rowspan value

DefaultVerticalAlignment

Changes the verticalAlignment in the default layout of the Cells added with method AddCell(string content).

public int DefaultVerticalAlignment { set; }

Property Value

int

the new alignment value

Dimension

Gets the dimension of this table

public Dimension Dimension { get; }

Property Value

Dimension

the dimension

ElementComplete

@since iText 2.0.8 @see com.lowagie.text.LargeElement#isComplete()

public bool ElementComplete { get; set; }

Property Value

bool

LastHeaderRow

Sets the horizontal Element.

public int LastHeaderRow { get; set; }

Property Value

int

the new value

Left

public override float Left { get; set; }

Property Value

float

Locked

Is the width a percentage (false) or an absolute width (true)?

public bool Locked { get; set; }

Property Value

bool

NextColumn

Returns the next column 0-based index where a new cell would be added. (contributed by dperezcar@fcc.es)

public int NextColumn { get; }

Property Value

int

y coordinate for the next row

NextRow

Returns the next row 0-based index where a new cell would be added. (contributed by dperezcar@fcc.es)

public int NextRow { get; }

Property Value

int

x coordinate for the next row

NotAddedYet

Indicates if this is the first time the section is added. @since iText2.0.8

public bool NotAddedYet { get; set; }

Property Value

bool

true if the section wasn't added yet

Offset

Get/set the offset of this table.

public float Offset { get; set; }

Property Value

float

the space between this table and the previous element.

Padding

Sets the cellpadding.

public float Padding { set; }

Property Value

float

the new value

ProportionalWidths

Gets the proportional widths of the columns in this Table.

public float[] ProportionalWidths { get; }

Property Value

float[]

the proportional widths of the columns in this Table

Right

public override float Right { get; set; }

Property Value

float

Size

methods to retrieve the membervariables

public int Size { get; }

Property Value

int

the number of rows in this Table

Spacing

Sets the cellspacing.

public float Spacing { set; }

Property Value

float

the new value

TableFitsPage

Allows you to control when a page break occurs.

public bool TableFitsPage { get; set; }

Property Value

bool

a value

Remarks

When a table doesn't fit a page, it is split in two parts. If you want to avoid this, you should set the tableFitsPage value to true.

Top

public override float Top { get; set; }

Property Value

float

Type

Gets the type of the text element.

public override int Type { get; }

Property Value

int

a type

Width

Get/set the table width (a percentage).

public override float Width { get; set; }

Property Value

float

the table width (a percentage)

Widths

Sets the widths of the different columns (percentages).

public float[] Widths { set; }

Property Value

float[]

an array with values

Examples

float[] widths = {2, 1, 1}; table.SetWidths(widths) The widths will be: a width of 50% for the first column, 25% for the second and third column.

Remarks

You can give up relative values of borderwidths. The sum of these values will be considered 100%. The values will be recalculated as percentages of this sum.

Methods

AddCell(string)

Adds a Cell to the Table.

public void AddCell(string content)

Parameters

content string

a string

Remarks

This is a shortcut for AddCell(Cell cell). The string will be converted to a Cell.

AddCell(string, Point)

Adds a Cell to the Table.

public void AddCell(string content, Point location)

Parameters

content string

a string

location Point

a point

Remarks

This is a shortcut for AddCell(Cell cell, System.Drawing.Point location). The string will be converted to a Cell.

AddCell(Cell)

Adds a Cell to the Table.

public void AddCell(Cell cell)

Parameters

cell Cell

a Cell

AddCell(Cell, int, int)

Adds a Cell to the Table at a certain row and column.

public void AddCell(Cell aCell, int row, int column)

Parameters

aCell Cell

The Cell to add

row int

The row where the Cell will be added

column int

The column where the Cell will be added

AddCell(Cell, object)

methods to add content to the table

public void AddCell(Cell aCell, object aLocation)

Parameters

aCell Cell

The Cell to add

aLocation object

The location where the Cell will be added

AddCell(Phrase)

Adds a Cell to the Table.

public void AddCell(Phrase content)

Parameters

content Phrase

a Phrase

Remarks

This is a shortcut for AddCell(Cell cell). The Phrase will be converted to a Cell.

AddCell(Phrase, Point)

Adds a Cell to the Table.

public void AddCell(Phrase content, Point location)

Parameters

content Phrase

a Phrase

location Point

a System.Drawing.Point

AddColumns(int)

Gives you the posibility to add columns.

public void AddColumns(int aColumns)

Parameters

aColumns int

the number of columns to add

Complete()

Will fill empty cells with valid blank Cells

public void Complete()

CreatePdfPTable()

Create a PdfPTable based on this Table object. @throws BadElementException

public PdfPTable CreatePdfPTable()

Returns

PdfPTable

a PdfPTable object

DeleteAllRows()

public void DeleteAllRows()

DeleteColumn(int)

Deletes a column in this table.

public void DeleteColumn(int column)

Parameters

column int

the number of the column that has to be deleted

DeleteLastRow()

Deletes all rows in this table. (contributed by dperezcar@fcc.es)

public bool DeleteLastRow()

Returns

bool

true if the row was deleted; false if not

DeleteRow(int)

Deletes a row.

public bool DeleteRow(int row)

Parameters

row int

the number of the row to delete

Returns

bool

true if the row was deleted; false if not

EndHeaders()

Marks the last row of the table headers.

public int EndHeaders()

Returns

int

the number of the last row of the table headers

FlushContent()

@since iText 2.0.8 @see com.lowagie.text.LargeElement#flushContent()

public void FlushContent()

GetBottom(float)

public override float GetBottom(float margin)

Parameters

margin float

Returns

float

GetElement(int, int)

returns the element at the position row, column (Cast to Cell or Table)

public object GetElement(int row, int column)

Parameters

row int
column int

Returns

object

an object

GetEnumerator()

Gets an Iterator of all the Rows.

public List<Row>.Enumerator GetEnumerator()

Returns

List<Row>.Enumerator

an IEnumerator

GetLeft(float)

public override float GetLeft(float margin)

Parameters

margin float

Returns

float

GetRight(float)

public override float GetRight(float margin)

Parameters

margin float

Returns

float

GetTop(float)

public override float GetTop(float margin)

Parameters

margin float

Returns

float

GetWidths(float, float)

Gets an array with the positions of the borders between every column.

public float[] GetWidths(float left, float totalWidth)

Parameters

left float

this is the position of the first border at the left (cellpadding not included)

totalWidth float

this is the space between the first border at the left and the last border at the right (cellpadding not included)

Returns

float[]

an array with borderpositions

Remarks

This method translates the widths expressed in percentages into the x-coordinate of the borders of the columns on a real document.

InsertTable(Table)

To put a table within the existing table at the current position generateTable will of course re-arrange the widths of the columns.

public void InsertTable(Table aTable)

Parameters

aTable Table

the table you want to insert

InsertTable(Table, Point)

To put a table within the existing table at the given position generateTable will of course re-arrange the widths of the columns.

public void InsertTable(Table aTable, Point p)

Parameters

aTable Table

the table you want to insert

p Point

a System.Drawing.Point

InsertTable(Table, int, int)

To put a table within the existing table at the given position generateTable will of course re-arrange the widths of the columns.

public void InsertTable(Table aTable, int row, int column)

Parameters

aTable Table

The Table to add

row int

The row where the Cell will be added

column int

The column where the Cell will be added

IsNestable()

@see com.lowagie.text.Element#isNestable() @since iText 2.0.8

public override bool IsNestable()

Returns

bool

Process(IElementListener)

Processes the element by adding it (or the different parts) to an IElementListener.

public override bool Process(IElementListener listener)

Parameters

listener IElementListener

an IElementListener

Returns

bool

true if the element was processed successfully

SetAlignment(string)

Gets all the chunks in this element.

public void SetAlignment(string alignment)

Parameters

alignment string

the new alignment as a string

SetWidths(int[])

Sets the widths of the different columns (percentages).

public void SetWidths(int[] widths)

Parameters

widths int[]

an array with values

Remarks

You can give up relative values of borderwidths. The sum of these values will be considered 100%. The values will be recalculated as percentages of this sum.