Table of Contents

Class Table

Namespace
iText.Layout.Element
Assembly
itext.layout.dll

A Table is a layout element that represents data in a two-dimensional grid.

public class Table : BlockElement<Table>, IAccessibleElement, IBlockElement, IAbstractElement, ILargeElement, IElement, IPropertyContainer
Inheritance
Table
Implements
Inherited Members

Remarks

A Table is a layout element that represents data in a two-dimensional grid. It is filled with cells , ordered in rows and columns.

It is an implementation of ILargeElement , which means it can be flushed to the canvas, in order to reclaim memory that is locked up.

Constructors

Table(int)

Constructs a Table with specified number of columns.

public Table(int numColumns)

Parameters

numColumns int

the number of columns, each column will have equal percent width.

Remarks

Constructs a Table with specified number of columns. The final column widths depend on selected table layout.
Since 7.0.2 table layout was introduced. Auto layout is default, except large tables. For large table fixed layout set implicitly.

Since 7.1 table will have undefined column widths, that will be determined during layout. In oder to set equal percent width as column width, use CreatePercentArray(int)

Note, the eventual columns width depends on selected layout, table width, cell's width, cell's min-widths, and cell's max-widths. Table layout algorithm has the same behaviour as expected for CSS table-layout property, where columnWidths is <colgroup>'s widths. For more information see SetAutoLayout() and SetFixedLayout().
See Also

Table(int, bool)

Constructs a Table with specified number of columns.

public Table(int numColumns, bool largeTable)

Parameters

numColumns int

the number of columns, each column will have equal percent width.

largeTable bool

whether parts of the table will be written before all data is added. Note, large table does not support auto layout, table width shall not be removed.

Remarks

Constructs a Table with specified number of columns. The final column widths depend on selected table layout.
Since 7.0.2 table layout algorithms were introduced. Auto layout is default, except large tables. For large table fixed layout set implicitly.
Since 7.1 table will have undefined column widths, that will be determined during layout. In oder to set equal percent width as column width, use CreatePercentArray(int)
Note, the eventual columns width depends on selected layout, table width, cell's width, cell's min-widths, and cell's max-widths. Table layout algorithm has the same behaviour as expected for CSS table-layout property, where columnWidths is <colgroup>'s widths. For more information see SetAutoLayout() and SetFixedLayout().

See Also

Table(float[])

Constructs a Table with the preferable column widths.

public Table(float[] pointColumnWidths)

Parameters

pointColumnWidths float[]

preferable column widths in points. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined.

Remarks

Constructs a Table with the preferable column widths.
Since 7.0.2 table layout algorithms were introduced. Auto layout is default.
Note, the eventual columns width depends on selected layout, table width, cell's width, cell's min-widths, and cell's max-widths. Table layout algorithm has the same behaviour as expected for CSS table-layout property, where columnWidths is <colgroup>'s widths. For more information see SetAutoLayout() and SetFixedLayout().

See Also

Table(float[], bool)

Constructs a Table with the preferable column widths.

public Table(float[] columnWidths, bool largeTable)

Parameters

columnWidths float[]

preferable column widths in points. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined.

largeTable bool

whether parts of the table will be written before all data is added. Note, large table does not support auto layout, table width shall not be removed.

Remarks

Constructs a Table with the preferable column widths.
Since 7.0.2 table layout algorithms were introduced. Auto layout is default, except large tables. For large table 100% width and fixed layout set implicitly.
Note, the eventual columns width depends on selected layout, table width, cell's width, cell's min-widths, and cell's max-widths. Table layout algorithm has the same behaviour as expected for CSS table-layout property, where columnWidths is <colgroup>'s widths. For more information see SetAutoLayout() and SetFixedLayout().

See Also

Table(UnitValue[])

Constructs a Table with the preferable column widths.

public Table(UnitValue[] columnWidths)

Parameters

columnWidths UnitValue[]

preferable column widths, points and/or percents. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined.

Remarks

Constructs a Table with the preferable column widths.
Since 7.0.2 table layout algorithms were introduced. Auto layout is default.
Note, the eventual columns width depends on selected layout, table width, cell's width, cell's min-widths, and cell's max-widths. Table layout algorithm has the same behaviour as expected for CSS table-layout property, where columnWidths is <colgroup>'s widths. For more information see SetAutoLayout() and SetFixedLayout().

See Also

Table(UnitValue[], bool)

Constructs a Table with the preferable column widths.

public Table(UnitValue[] columnWidths, bool largeTable)

Parameters

columnWidths UnitValue[]

preferable column widths, points and/or percents. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined.

largeTable bool

whether parts of the table will be written before all data is added. Note, large table does not support auto layout, table width shall not be removed.

Remarks

Constructs a Table with the preferable column widths.
Since 7.0.2 table layout algorithms were introduced. Auto layout is default, except large tables. For large table 100% width and fixed layout set implicitly.
Note, the eventual columns width depends on selected layout, table width, cell's width, cell's min-widths, and cell's max-widths. Table layout algorithm has the same behaviour as expected for CSS table-layout property, where columnWidths is <colgroup>'s widths. For more information see SetAutoLayout() and SetFixedLayout().

See Also

Fields

tagProperties

protected DefaultAccessibilityProperties tagProperties

Field Value

DefaultAccessibilityProperties

Methods

AddCell(string)

Adds a new cell with received string as a content.

public virtual Table AddCell(string content)

Parameters

content string

a string to add to the cell and then to the table

Returns

Table

this element

AddCell(Cell)

Adds a new cell to the table.

public virtual Table AddCell(Cell cell)

Parameters

cell Cell

Cell to add.

Returns

Table

this element

Remarks

Adds a new cell to the table. The implementation decides for itself which row the cell will be placed on.

AddCell(Image)

Adds a new cell with received image as a content.

public virtual Table AddCell(Image image)

Parameters

image Image

an image to add to the cell and then to the table

Returns

Table

this element

AddCell<T>(BlockElement<T>)

Adds a new cell with received blockElement as a content.

public virtual Table AddCell<T>(BlockElement<T> blockElement) where T : IElement

Parameters

blockElement BlockElement<T>

a blockElement to add to the cell and then to the table

Returns

Table

this element

Type Parameters

T

IElement instance

AddFooterCell(string)

Adds a new cell with received string as a content to the footer of the table.

public virtual Table AddFooterCell(string content)

Parameters

content string

a content string to be added to a footer cell

Returns

Table

this element

Remarks

Adds a new cell with received string as a content to the footer of the table. The footer will be displayed in the bottom of every area of this table. See also SetSkipLastFooter(bool).

AddFooterCell(Cell)

Adds a new cell to the footer of the table.

public virtual Table AddFooterCell(Cell footerCell)

Parameters

footerCell Cell

a footer cell

Returns

Table

this element

Remarks

Adds a new cell to the footer of the table. The footer will be displayed in the bottom of every area of this table. See also SetSkipLastFooter(bool).

AddFooterCell(Image)

Adds a new cell with received image as a content to the footer of the table.

public virtual Table AddFooterCell(Image image)

Parameters

image Image

an image to be added to a footer cell

Returns

Table

this element

Remarks

Adds a new cell with received image as a content to the footer of the table. The footer will be displayed in the bottom of every area of this table. See also SetSkipLastFooter(bool).

AddFooterCell<T>(BlockElement<T>)

Adds a new cell with received blockElement as a content to the footer of the table.

public virtual Table AddFooterCell<T>(BlockElement<T> blockElement) where T : IElement

Parameters

blockElement BlockElement<T>

an element to be added to a footer cell

Returns

Table

this element

Type Parameters

T

IElement instance

Remarks

Adds a new cell with received blockElement as a content to the footer of the table. The footer will be displayed in the bottom of every area of this table. See also SetSkipLastFooter(bool).

AddHeaderCell(string)

Adds a new cell with received string as a content to the header of the table.

public virtual Table AddHeaderCell(string content)

Parameters

content string

a string to be added to a header cell

Returns

Table

this element

Remarks

Adds a new cell with received string as a content to the header of the table. The header will be displayed in the top of every area of this table. See also SetSkipFirstHeader(bool).

AddHeaderCell(Cell)

Adds a new cell to the header of the table.

public virtual Table AddHeaderCell(Cell headerCell)

Parameters

headerCell Cell

a header cell to be added

Returns

Table

this element

Remarks

Adds a new cell to the header of the table. The header will be displayed in the top of every area of this table. See also SetSkipFirstHeader(bool).

AddHeaderCell(Image)

Adds a new cell with received image to the header of the table.

public virtual Table AddHeaderCell(Image image)

Parameters

image Image

an element to be added to a header cell

Returns

Table

this element

Remarks

Adds a new cell with received image to the header of the table. The header will be displayed in the top of every area of this table. See also SetSkipFirstHeader(bool).

AddHeaderCell<T>(BlockElement<T>)

Adds a new cell with received blockElement as a content to the header of the table.

public virtual Table AddHeaderCell<T>(BlockElement<T> blockElement) where T : IElement

Parameters

blockElement BlockElement<T>

an element to be added to a header cell

Returns

Table

this element

Type Parameters

T

any IElement

Remarks

Adds a new cell with received blockElement as a content to the header of the table. The header will be displayed in the top of every area of this table. See also SetSkipFirstHeader(bool).

Complete()

Indicates that all the desired content has been added to this large element and no more content will be added.

public virtual void Complete()

Remarks

Indicates that all the desired content has been added to this large element and no more content will be added. After this method is called, more precise rendering is activated. For instance, a table may have a SetSkipLastFooter(bool) method set to true, and in case of large table on Flush() we do not know if any more content will be added, so we might not place the content in the bottom of the page where it would fit, but instead add a footer, and place that content in the start of the page. Technically such result would look all right, but it would be more concise if we placed the content in the bottom and did not start new page. For such cases to be renderered more accurately, one can call complete() when some content is still there and not flushed.

CreateRendererSubTree()

Creates a renderer subtree with root in the current table element.

public override IRenderer CreateRendererSubTree()

Returns

IRenderer

a TableRenderer subtree for this element

Remarks

Creates a renderer subtree with root in the current table element. Compared to GetRenderer() , the renderer returned by this method should contain all the child renderers for children of the current element.

Flush()

Writes the newly added content to the document.

public virtual void Flush()

FlushContent()

Flushes the content which has just been added to the document.

public virtual void FlushContent()

Remarks

Flushes the content which has just been added to the document. This is a method for internal usage and is called automatically by the document.

GetAccessibilityProperties()

public override AccessibilityProperties GetAccessibilityProperties()

Returns

AccessibilityProperties

GetCaption()

Gets the table's caption.

public virtual Div GetCaption()

Returns

Div

the table's caption.

GetCell(int, int)

Returns a cell as specified by its location.

public virtual Cell GetCell(int row, int column)

Parameters

row int

the row of the cell. indexes are zero-based

column int

the column of the cell. indexes are zero-based

Returns

Cell

the cell at the specified position.

Remarks

Returns a cell as specified by its location. If the cell is in a col-span or row-span and is not the top left cell, then null is returned.

GetColumnWidth(int)

Returns the column width for the specified column.

public virtual UnitValue GetColumnWidth(int column)

Parameters

column int

index of the column

Returns

UnitValue

the width of the column

GetFooter()

Gets the footer of the table.

public virtual Table GetFooter()

Returns

Table

table footer or null , if AddFooterCell(Cell) hasn't been called.

Remarks

Gets the footer of the table. The footer is represented as a distinct table and might have its own properties.

GetHeader()

Gets the header of the table.

public virtual Table GetHeader()

Returns

Table

table header or null , if AddHeaderCell(Cell) hasn't been called.

Remarks

Gets the header of the table. The header is represented as a distinct table and might have its own properties.

GetLastRowBottomBorder()

Gets the markup properties of the bottom border of the (current) last row.

public virtual IList<Border> GetLastRowBottomBorder()

Returns

IList<Border>

an array of Border objects

GetNumberOfColumns()

Returns the number of columns.

public virtual int GetNumberOfColumns()

Returns

int

the number of columns.

GetNumberOfRows()

Returns the number of rows.

public virtual int GetNumberOfRows()

Returns

int

the number of rows.

GetRenderer()

Gets a table renderer for this element.

public override IRenderer GetRenderer()

Returns

IRenderer

a table renderer for this element

Remarks

Gets a table renderer for this element. Note that this method can be called more than once. By default each element should define its own renderer, but the renderer can be overridden by SetNextRenderer(IRenderer) method call.

GetRowGroups()

Returns the list of all row groups.

protected virtual IList<Table.RowRange> GetRowGroups()

Returns

IList<Table.RowRange>

a list of a Table.RowRange which holds the row numbers of a section of a table

IsComplete()

public virtual bool IsComplete()

Returns

bool

IsSkipFirstHeader()

Tells you if the first header needs to be skipped (for instance if the header says "continued from the previous page").

public virtual bool IsSkipFirstHeader()

Returns

bool

Value of property skipFirstHeader.

IsSkipLastFooter()

Tells you if the last footer needs to be skipped (for instance if the footer says "continued on the next page")

public virtual bool IsSkipLastFooter()

Returns

bool

Value of property skipLastFooter.

MakeNewRenderer()

protected override IRenderer MakeNewRenderer()

Returns

IRenderer

SetAutoLayout()

Set auto layout.

public virtual Table SetAutoLayout()

Returns

Table

this element.

Remarks

Set auto layout. Analog of table-layout:auto CSS property.
Note, large table does not support auto layout.

Algorithm principles.
1. Column width cannot be less, than min-width of any cell in the column (calculated by layout).
2. Specified table width has higher priority, than sum of column and cell widths.
3. Percent value of cell and column width has higher priority, than point value.
4. Cell width has higher priority, than column width.
5. If column has no width, it will try to reach max-value (calculated by layout).

SetBorderCollapse(BorderCollapsePropertyValue)

Sets the type of border collapse.

public virtual Table SetBorderCollapse(BorderCollapsePropertyValue collapsePropertyValue)

Parameters

collapsePropertyValue BorderCollapsePropertyValue

BorderCollapsePropertyValue to be set as the border collapse type

Returns

Table

this Table

SetCaption(Div)

Sets the table's caption.

public virtual Table SetCaption(Div caption)

Parameters

caption Div

The element to be set as a caption.

Returns

Table

this element

Remarks

Sets the table's caption. If there is no CAPTION_SIDE set (note that it's an inheritable property), TOP will be used. Also the CAPTION will be set on the element.

SetCaption(Div, CaptionSide)

Sets the table's caption and its caption side.

public virtual Table SetCaption(Div caption, CaptionSide side)

Parameters

caption Div

The element to be set as a caption.

side CaptionSide

The caption side to be set on the caption.

Returns

Table

this element

Remarks

Sets the table's caption and its caption side. Also the CAPTION will be set on the element.

SetDocument(Document)

public virtual void SetDocument(Document document)

Parameters

document Document

SetExtendBottomRow(bool)

Defines whether the Table should be extended to occupy all the space left in the available area in case it is the last element in this area.

public virtual Table SetExtendBottomRow(bool isExtended)

Parameters

isExtended bool

defines whether the Table should be extended

Returns

Table

this Table

SetExtendBottomRowOnSplit(bool)

Defines whether the Table should be extended to occupy all the space left in the available area in case the area has been split and it is the last element in the split part of this area.

public virtual Table SetExtendBottomRowOnSplit(bool isExtended)

Parameters

isExtended bool

defines whether the Table should be extended

Returns

Table

this Table

SetFixedLayout()

Set fixed layout.

public virtual Table SetFixedLayout()

Returns

Table

this element.

Remarks

Set fixed layout. Analog of table-layout:fixed CSS property. Note, the table must have width property, otherwise auto layout will be used.

Algorithm description
1. Scan columns for width property and set it. All the rest columns get undefined value. Column width includes borders and paddings. Columns have set in constructor, analog of <colgroup> element in HTML.
2. Scan the very first row of table for width property and set it to undefined columns. Cell width has lower priority in comparing with column. Cell width doesn't include borders and paddings.
2.1 If cell has colspan and all columns are undefined, each column will get equal width: width/colspan.
2.2 If some columns already have width, equal remain (original width minus existed) width will be added remainWidth/colspan to each column.
3. If sum of columns is less, than table width, there are two options:
3.1. If undefined columns still exist, they will get the rest remaining width.
3.2. Otherwise all columns will be expanded proportionally based on its width.
4. If sum of columns is greater, than table width, nothing to do.

SetHorizontalBorderSpacing(float)

Sets the horizontal spacing between this table 's cells.

public virtual Table SetHorizontalBorderSpacing(float spacing)

Parameters

spacing float

a horizontal spacing between this table 's cells

Returns

Table

this Table

SetSkipFirstHeader(bool)

Skips the printing of the first header.

public virtual Table SetSkipFirstHeader(bool skipFirstHeader)

Parameters

skipFirstHeader bool

New value of property skipFirstHeader.

Returns

Table

this element

Remarks

Skips the printing of the first header. Used when printing tables in succession belonging to the same printed table aspect.

SetSkipLastFooter(bool)

Skips the printing of the last footer.

public virtual Table SetSkipLastFooter(bool skipLastFooter)

Parameters

skipLastFooter bool

New value of property skipLastFooter.

Returns

Table

this element

Remarks

Skips the printing of the last footer. Used when printing tables in succession belonging to the same printed table aspect.

SetVerticalBorderSpacing(float)

Sets the vertical spacing between this table 's cells.

public virtual Table SetVerticalBorderSpacing(float spacing)

Parameters

spacing float

a vertical spacing between this table 's cells

Returns

Table

this Table

StartNewRow()

Starts new row.

public virtual Table StartNewRow()

Returns

Table

this element

Remarks

Starts new row. This mean that next cell will be added at the beginning of next line.

UseAllAvailableWidth()

Set WIDTH = 100%.

public virtual Table UseAllAvailableWidth()

Returns

Table

this element