Class Table
- All Implemented Interfaces:
-
IAbstractElement
,IBlockElement
,IElement
,ILargeElement
,IPropertyContainer
,IAccessibleElement
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
A simple object which holds the row numbers of a section of a table. -
Field Summary
Fields inherited from class com.itextpdf.layout.element.AbstractElement
childElements, nextRenderer, styles
Fields inherited from class com.itextpdf.layout.ElementPropertyContainer
properties
-
Constructor Summary
ConstructorDescriptionTable
(float[] pointColumnWidths) Constructs aTable
with the preferable column widths.Table
(float[] columnWidths, boolean largeTable) Constructs aTable
with the preferable column widths.Table
(int numColumns) Constructs aTable
with specified number of columns.Table
(int numColumns, boolean largeTable) Constructs aTable
with specified number of columns.Constructs aTable
with the preferable column widths.Constructs aTable
with the preferable column widths. -
Method Summary
Modifier and TypeMethodDescriptionIElement>
TableaddCell
(BlockElement blockElement) Adds a new cell with received blockElement as a content.Adds a new cell to the table.Adds a new cell with received image as a content.Adds a new cell with received string as a content.IElement>
TableaddFooterCell
(BlockElement blockElement) Adds a new cell with received blockElement as a content to the footer of the table.addFooterCell
(Cell footerCell) Adds a new cell to the footer of the table.addFooterCell
(Image image) Adds a new cell with received image as a content to the footer of the table.addFooterCell
(String content) Adds a new cell with received string as a content to the footer of the table.IElement>
TableaddHeaderCell
(BlockElement blockElement) Adds a new cell with received blockElement as a content to the header of the table.addHeaderCell
(Cell headerCell) Adds a new cell to the header of the table.addHeaderCell
(Image image) Adds a new cell with received image to the header of the table.addHeaderCell
(String content) Adds a new cell with received string as a content to the header of the table.void
complete()
Indicates that all the desired content has been added to this large element and no more content will be added.Creates a renderer subtree with root in the current table element.void
flush()
Writes the newly added content to the document.void
Flushes the content which has just been added to the document.Gets theaccessibility properties
.Gets the table's caption.getCell
(int row, int column) Returns a cell as specified by its location.getColumnWidth
(int column) Returns the column width for the specified column.Gets the footer of the table.Gets the header of the table.Gets the markup properties of the bottom border of the (current) last row.int
Returns the number of columns.int
Returns the number of rows.Gets a table renderer for this element.protected List<Table.RowRange>
Returns the list of all row groups.boolean
Checks whether an element has already been marked as complete.boolean
Tells you if the first header needs to be skipped (for instance if the header says "continued from the previous page").boolean
Tells you if the last footer needs to be skipped (for instance if the footer says "continued on the next page")protected IRenderer
Creates new renderer instance.Set auto layout.setBorderCollapse
(BorderCollapsePropertyValue collapsePropertyValue) Sets the type of border collapse.setCaption
(Div caption) Sets the table's caption.setCaption
(Div caption, CaptionSide side) Sets the table's caption and its caption side.void
setDocument
(Document document) Sets the document this element is bound to.setExtendBottomRow
(boolean isExtended) Defines whether theTable
should be extended to occupy all the space left in the available area in case it is the last element in this area.setExtendBottomRowOnSplit
(boolean isExtended) Defines whether theTable
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.Set fixed layout.setHorizontalBorderSpacing
(float spacing) setSkipFirstHeader
(boolean skipFirstHeader) Skips the printing of the first header.setSkipLastFooter
(boolean skipLastFooter) Skips the printing of the last footer.setVerticalBorderSpacing
(float spacing) Starts new row.SetProperty.WIDTH
= 100%.Methods inherited from class com.itextpdf.layout.element.BlockElement
getDefaultProperty, getHeight, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, getWidth, isKeepTogether, isKeepWithNext, setHeight, setHeight, setKeepTogether, setKeepWithNext, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMargins, setMarginTop, setMaxHeight, setMaxHeight, setMaxWidth, setMaxWidth, setMinHeight, setMinHeight, setMinWidth, setMinWidth, setNeutralRole, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRight, setPaddings, setPaddingTop, setRotationAngle, setRotationAngle, setSpacingRatio, setVerticalAlignment, setWidth, setWidth
Methods inherited from class com.itextpdf.layout.element.AbstractElement
addStyle, getChildren, getProperty, hasProperty, isEmpty, setAction, setNextRenderer, setPageNumber
Methods inherited from class com.itextpdf.layout.ElementPropertyContainer
deleteOwnProperty, getOwnProperty, getSplitCharacters, getStrokeColor, getStrokeWidth, getTextRenderingMode, hasOwnProperty, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundImage, setBackgroundImage, setBaseDirection, setBold, setBorder, setBorderBottom, setBorderBottomLeftRadius, setBorderBottomRightRadius, setBorderLeft, setBorderRadius, setBorderRight, setBorderTop, setBorderTopLeftRadius, setBorderTopRightRadius, setCharacterSpacing, setDestination, setFixedPosition, setFixedPosition, setFixedPosition, setFixedPosition, setFont, setFontColor, setFontColor, setFontFamily, setFontFamily, setFontKerning, setFontScript, setFontSize, setHorizontalAlignment, setHyphenation, setItalic, setLineThrough, setOpacity, setProperty, setRelativePosition, setSplitCharacters, setStrokeColor, setStrokeWidth, setTextAlignment, setTextRenderingMode, setUnderline, setUnderline, setUnderline, setUnderline, setWordSpacing
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.itextpdf.layout.element.IAbstractElement
getChildren
Methods inherited from interface com.itextpdf.layout.element.IElement
setNextRenderer
Methods inherited from interface com.itextpdf.layout.IPropertyContainer
deleteOwnProperty, getDefaultProperty, getOwnProperty, getProperty, hasOwnProperty, hasProperty, setProperty
-
Field Details
-
tagProperties
-
-
Constructor Details
-
Table
public Table(float[] columnWidths, boolean largeTable) Constructs aTable
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, wherecolumnWidths
is's widths. For more information see setAutoLayout()
andsetFixedLayout()
.- Parameters:
-
columnWidths
- preferable column widths in points. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined. -
largeTable
- 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. - See Also:
-
Table
Constructs aTable
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, wherecolumnWidths
is's widths. For more information see setAutoLayout()
andsetFixedLayout()
.- Parameters:
-
columnWidths
- preferable column widths, points and/or percents. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined. -
largeTable
- 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. - See Also:
-
Table
Constructs aTable
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, wherecolumnWidths
is's widths. For more information see setAutoLayout()
andsetFixedLayout()
.- Parameters:
-
columnWidths
- preferable column widths, points and/or percents. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined. - See Also:
-
Table
public Table(float[] pointColumnWidths) Constructs aTable
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, wherecolumnWidths
is's widths. For more information see setAutoLayout()
andsetFixedLayout()
.- Parameters:
-
pointColumnWidths
- preferable column widths in points. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined. - See Also:
-
Table
public Table(int numColumns, boolean largeTable) Constructs aTable
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, useUnitValue.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, wherecolumnWidths
is's widths. For more information see setAutoLayout()
andsetFixedLayout()
.- Parameters:
-
numColumns
- the number of columns, each column will have equal percent width. -
largeTable
- 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. - See Also:
-
Table
public Table(int numColumns) Constructs aTable
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
UnitValue.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's widths. For more information see setAutoLayout()
andsetFixedLayout()
.- Parameters:
-
numColumns
- the number of columns, each column will have equal percent width. - See Also:
-
-
Method Details
-
setFixedLayout
Set fixed layout. Analog oftable-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
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 addedremainWidth/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.- Returns:
- this element.
-
setAutoLayout
Set auto layout. Analog oftable-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).- Returns:
- this element.
-
useAllAvailableWidth
SetProperty.WIDTH
= 100%.- Returns:
- this element
-
getColumnWidth
Returns the column width for the specified column.- Parameters:
-
column
- index of the column - Returns:
- the width of the column
-
getNumberOfColumns
public int getNumberOfColumns()Returns the number of columns.- Returns:
- the number of columns.
-
getNumberOfRows
public int getNumberOfRows()Returns the number of rows.- Returns:
- the number of rows.
-
addHeaderCell
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 alsosetSkipFirstHeader(boolean)
.- Parameters:
-
headerCell
- a header cell to be added - Returns:
- this element
-
addHeaderCell
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 alsosetSkipFirstHeader(boolean)
.- Type Parameters:
-
T
- any IElement - Parameters:
-
blockElement
- an element to be added to a header cell - Returns:
- this element
-
addHeaderCell
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 alsosetSkipFirstHeader(boolean)
.- Parameters:
-
image
- an element to be added to a header cell - Returns:
- this element
-
addHeaderCell
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 alsosetSkipFirstHeader(boolean)
.- Parameters:
-
content
- a string to be added to a header cell - Returns:
- this element
-
getHeader
Gets the header of the table. The header is represented as a distinct table and might have its own properties.- Returns:
-
table header or
null
, ifaddHeaderCell(Cell)
hasn't been called.
-
isSkipFirstHeader
public boolean isSkipFirstHeader()Tells you if the first header needs to be skipped (for instance if the header says "continued from the previous page").- Returns:
- Value of property skipFirstHeader.
-
setSkipFirstHeader
Skips the printing of the first header. Used when printing tables in succession belonging to the same printed table aspect.- Parameters:
-
skipFirstHeader
- New value of property skipFirstHeader. - Returns:
- this element
-
setCaption
Sets the table's caption. If there is noProperty.CAPTION_SIDE
set (note that it's an inheritable property),CaptionSide.TOP
will be used. Also theStandardRoles.CAPTION
will be set on the element.- Parameters:
-
caption
- The element to be set as a caption. - Returns:
- this element
-
setCaption
Sets the table's caption and its caption side. Also theStandardRoles.CAPTION
will be set on the element.- Parameters:
-
caption
- The element to be set as a caption. -
side
- The caption side to be set on the caption. - Returns:
- this element
-
getCaption
Gets the table's caption.- Returns:
- the table's caption.
-
startNewRow
Starts new row. This mean that next cell will be added at the beginning of next line.- Returns:
- this element
-
addCell
Adds a new cell to the table. The implementation decides for itself which row the cell will be placed on.- Parameters:
-
cell
-Cell
to add. - Returns:
- this element
-
addCell
Adds a new cell with received blockElement as a content.- Type Parameters:
-
T
- IElement instance - Parameters:
-
blockElement
- a blockElement to add to the cell and then to the table - Returns:
- this element
-
addCell
Adds a new cell with received image as a content.- Parameters:
-
image
- an image to add to the cell and then to the table - Returns:
- this element
-
addCell
Adds a new cell with received string as a content.- Parameters:
-
content
- a string to add to the cell and then to the table - Returns:
- this element
-
getCell
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, thennull
is returned.- Parameters:
-
row
- the row of the cell. indexes are zero-based -
column
- the column of the cell. indexes are zero-based - Returns:
- the cell at the specified position.
-
createRendererSubTree
Creates a renderer subtree with root in the current table element. Compared togetRenderer()
, the renderer returned by this method should contain all the child renderers for children of the current element.- Specified by:
-
createRendererSubTree
in interfaceIElement
- Overrides:
-
createRendererSubTree
in classAbstractElement<Table>
- Returns:
-
a
TableRenderer
subtree for this element
-
getRenderer
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 byAbstractElement.setNextRenderer(IRenderer)
method call.- Specified by:
-
getRenderer
in interfaceIElement
- Overrides:
-
getRenderer
in classAbstractElement<Table>
- Returns:
- a table renderer for this element
-
isComplete
public boolean isComplete()Description copied from interface:ILargeElement
Checks whether an element has already been marked as complete.- Specified by:
-
isComplete
in interfaceILargeElement
- Returns:
- the completion marker boolean
-
complete
public void complete()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 asetSkipLastFooter(boolean)
method set to true, and in case of large table onflush()
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.- Specified by:
-
complete
in interfaceILargeElement
-
flush
public void flush()Writes the newly added content to the document.- Specified by:
-
flush
in interfaceILargeElement
-
flushContent
public void flushContent()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.- Specified by:
-
flushContent
in interfaceILargeElement
-
setDocument
Description copied from interface:ILargeElement
Sets the document this element is bound to. We cannot write a large element into several documents simultaneously because we would need more bulky interfaces for this feature. For now we went for simplicity.- Specified by:
-
setDocument
in interfaceILargeElement
- Parameters:
-
document
- the document
-
getLastRowBottomBorder
Gets the markup properties of the bottom border of the (current) last row.- Returns:
-
an array of
Border
objects
-
setExtendBottomRow
Defines whether theTable
should be extended to occupy all the space left in the available area in case it is the last element in this area. -
setExtendBottomRowOnSplit
Defines whether theTable
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. -
setBorderCollapse
Sets the type of border collapse.- Parameters:
-
collapsePropertyValue
-BorderCollapsePropertyValue
to be set as the border collapse type - Returns:
-
this
Table
-
setHorizontalBorderSpacing
-
setVerticalBorderSpacing
-
getAccessibilityProperties
Description copied from interface:IAccessibleElement
Gets theaccessibility properties
. See alsoIAccessibleElement
.- Specified by:
-
getAccessibilityProperties
in interfaceIAccessibleElement
- Returns:
- an interface that allows to specify properties of a tagged element in Tagged PDF.
-
makeNewRenderer
Description copied from class:AbstractElement
Creates new renderer instance.- Specified by:
-
makeNewRenderer
in classAbstractElement<Table>
- Returns:
-
new
IRenderer
-
getRowGroups
Returns the list of all row groups.- Returns:
-
a list of a
Table.RowRange
which holds the row numbers of a section of a table
-