public class Table extends BlockElement<Table> implements ILargeElement
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.
Modifier and Type | Class and Description |
---|---|
static class |
Table.RowRange
A simple object which holds the row numbers of a section of a table.
|
Modifier and Type | Field and Description |
---|---|
protected DefaultAccessibilityProperties |
tagProperties |
childElements, nextRenderer, styles
properties
Constructor and Description |
---|
Table(float[] pointColumnWidths)
Constructs a Table with the preferable column widths.
|
Table(float[] columnWidths, boolean largeTable)
Constructs a Table with the preferable column widths.
|
Table(int numColumns)
Constructs a Table with specified number of columns.
|
Table(int numColumns, boolean largeTable)
Constructs a Table with specified number of columns.
|
Table(UnitValue[] columnWidths)
Constructs a Table with the preferable column widths.
|
Table(UnitValue[] columnWidths, boolean largeTable)
Constructs a Table with the preferable column widths.
|
Modifier and Type | Method and Description |
---|---|
|
addCell(BlockElement
Adds a new cell with received blockElement as a content.
|
Table |
addCell(Cell cell)
Adds a new cell to the table.
|
Table |
addCell(Image image)
Adds a new cell with received image as a content.
|
Table |
addCell(String content)
Adds a new cell with received string as a content.
|
|
addFooterCell(BlockElement
Adds a new cell with received blockElement as a content to the footer of the table.
|
Table |
addFooterCell(Cell footerCell)
Adds a new cell to the footer of the table.
|
Table |
addFooterCell(Image image)
Adds a new cell with received image as a content to the footer of the table.
|
Table |
addFooterCell(String content)
Adds a new cell with received string as a content to the footer of the table.
|
|
addHeaderCell(BlockElement
Adds a new cell with received blockElement as a content to the header of the table.
|
Table |
addHeaderCell(Cell headerCell)
Adds a new cell to the header of the table.
|
Table |
addHeaderCell(Image image)
Adds a new cell with received image to the header of the table.
|
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.
|
IRenderer |
createRendererSubTree()
Creates a renderer subtree with root in the current table element.
|
void |
flush()
Writes the newly added content to the document.
|
void |
flushContent()
Flushes the content which has just been added to the document.
|
AccessibilityProperties |
getAccessibilityProperties()
Gets the accessibility properties .
|
Div |
getCaption()
Gets the table's caption.
|
Cell |
getCell(int row, int column)
Returns a cell as specified by its location.
|
UnitValue |
getColumnWidth(int column)
Returns the column width for the specified column.
|
Table |
getFooter()
Gets the footer of the table.
|
Table |
getHeader()
Gets the header of the table.
|
List<Border> |
getLastRowBottomBorder()
Gets the markup properties of the bottom border of the (current) last row.
|
int |
getNumberOfColumns()
Returns the number of columns.
|
int |
getNumberOfRows()
Returns the number of rows.
|
IRenderer |
getRenderer()
Gets a table renderer for this element.
|
protected List<Table.RowRange> |
getRowGroups()
Returns the list of all row groups.
|
boolean |
isComplete()
Checks whether an element has already been marked as complete.
|
boolean |
isSkipFirstHeader()
Tells you if the first header needs to be skipped (for instance if the header says "continued from the previous page").
|
boolean |
isSkipLastFooter()
Tells you if the last footer needs to be skipped (for instance if the footer says "continued on the next page")
|
protected IRenderer |
makeNewRenderer()
Creates new renderer instance.
|
Table |
setAutoLayout()
Set auto layout.
|
Table |
setBorderCollapse(BorderCollapsePropertyValue collapsePropertyValue)
Sets the type of border collapse.
|
Table |
setCaption(Div caption)
Sets the table's caption.
|
Table |
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.
|
Table |
setExtendBottomRow(boolean isExtended)
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.
|
Table |
setExtendBottomRowOnSplit(boolean isExtended)
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.
|
Table |
setFixedLayout()
Set fixed layout.
|
Table |
setHorizontalBorderSpacing(float spacing)
|
Table |
setSkipFirstHeader(boolean skipFirstHeader)
Skips the printing of the first header.
|
Table |
setSkipLastFooter(boolean skipLastFooter)
Skips the printing of the last footer.
|
Table |
setVerticalBorderSpacing(float spacing)
|
Table |
startNewRow()
Starts new row.
|
Table |
useAllAvailableWidth()
Set Property.WIDTH = 100%.
|
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
addStyle, getChildren, getProperty, hasProperty, isEmpty, setAction, setNextRenderer, setPageNumber
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setNextRenderer
deleteOwnProperty, getDefaultProperty, getOwnProperty, getProperty, hasOwnProperty, hasProperty, setProperty
getChildren
protected DefaultAccessibilityProperties tagProperties
public Table(float[] columnWidths, boolean largeTable)
Table
with the preferable column widths.
columnWidths
is setAutoLayout()
and setFixedLayout()
.
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.
setAutoLayout()
, setFixedLayout()
public Table(UnitValue[] columnWidths, boolean largeTable)
Table
with the preferable column widths.
columnWidths
is setAutoLayout()
and setFixedLayout()
.
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.
setAutoLayout()
, setFixedLayout()
public Table(UnitValue[] columnWidths)
Table
with the preferable column widths.
columnWidths
is setAutoLayout()
and setFixedLayout()
.
columnWidths
- preferable column widths, points and/or percents. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined.
setAutoLayout()
, setFixedLayout()
public Table(float[] pointColumnWidths)
Table
with the preferable column widths.
columnWidths
is setAutoLayout()
and setFixedLayout()
.
pointColumnWidths
- preferable column widths in points. Values must be greater than or equal to zero, otherwise it will be interpreted as undefined.
setAutoLayout()
, setFixedLayout()
public Table(int numColumns, boolean largeTable)
Table
with specified number of columns. The final column widths depend on selected table layout.
UnitValue.createPercentArray(int)
columnWidths
is setAutoLayout()
and setFixedLayout()
.
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.
setAutoLayout()
, setFixedLayout()
public Table(int numColumns)
Table
with specified number of columns. The final column widths depend on selected table layout.
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
setAutoLayout()
and setFixedLayout()
.
numColumns
- the number of columns, each column will have equal percent width.
setAutoLayout()
, setFixedLayout()
public Table setFixedLayout()
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
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.
public Table setAutoLayout()
table-layout:auto
CSS property.
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).
public Table useAllAvailableWidth()
Property.WIDTH
= 100%.
public UnitValue getColumnWidth(int column)
column
- index of the column
public int getNumberOfColumns()
public int getNumberOfRows()
public Table addHeaderCell(Cell headerCell)
setSkipFirstHeader(boolean)
.
headerCell
- a header cell to be added
publicIElement> Table addHeaderCell(BlockElement blockElement)
setSkipFirstHeader(boolean)
.
T
- any IElement
blockElement
- an element to be added to a header cell
public Table addHeaderCell(Image image)
setSkipFirstHeader(boolean)
.
image
- an element to be added to a header cell
public Table addHeaderCell(String content)
setSkipFirstHeader(boolean)
.
content
- a string to be added to a header cell
public Table getHeader()
null
, if addHeaderCell(Cell)
hasn't been called.
public Table addFooterCell(Cell footerCell)
setSkipLastFooter(boolean)
.
footerCell
- a footer cell
publicIElement> Table addFooterCell(BlockElement blockElement)
setSkipLastFooter(boolean)
.
T
- IElement instance
blockElement
- an element to be added to a footer cell
public Table addFooterCell(Image image)
setSkipLastFooter(boolean)
.
image
- an image to be added to a footer cell
public Table addFooterCell(String content)
setSkipLastFooter(boolean)
.
content
- a content string to be added to a footer cell
public Table getFooter()
null
, if addFooterCell(Cell)
hasn't been called.
public boolean isSkipFirstHeader()
public Table setSkipFirstHeader(boolean skipFirstHeader)
skipFirstHeader
- New value of property skipFirstHeader.
public boolean isSkipLastFooter()
public Table setSkipLastFooter(boolean skipLastFooter)
skipLastFooter
- New value of property skipLastFooter.
public Table setCaption(Div caption)
Property.CAPTION_SIDE
set (note that it's an inheritable property), CaptionSide.TOP
will be used. Also the StandardRoles.CAPTION
will be set on the element.
caption
- The element to be set as a caption.
public Table setCaption(Div caption, CaptionSide side)
StandardRoles.CAPTION
will be set on the element.
caption
- The element to be set as a caption.
side
- The caption side to be set on the caption.
public Div getCaption()
public Table startNewRow()
public Table addCell(Cell cell)
cell
- Cell
to add.
publicIElement> Table addCell(BlockElement blockElement)
T
- IElement instance
blockElement
- a blockElement to add to the cell and then to the table
public Table addCell(Image image)
image
- an image to add to the cell and then to the table
public Table addCell(String content)
content
- a string to add to the cell and then to the table
public Cell getCell(int row, int column)
null
is returned.
row
- the row of the cell. indexes are zero-based
column
- the column of the cell. indexes are zero-based
public IRenderer createRendererSubTree()
getRenderer()
, the renderer returned by this method should contain all the child renderers for children of the current element.
createRendererSubTree
in interface IElement
createRendererSubTree
in class AbstractElement<Table>
TableRenderer
subtree for this element
public IRenderer getRenderer()
AbstractElement.setNextRenderer(IRenderer)
method call.
getRenderer
in interface IElement
getRenderer
in class AbstractElement<Table>
public boolean isComplete()
ILargeElement
isComplete
in interface ILargeElement
public void complete()
setSkipLastFooter(boolean)
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.
complete
in interface ILargeElement
public void flush()
flush
in interface ILargeElement
public void flushContent()
flushContent
in interface ILargeElement
public void setDocument(Document document)
ILargeElement
setDocument
in interface ILargeElement
document
- the document
public List<Border> getLastRowBottomBorder()
Border
objects
public Table setExtendBottomRow(boolean isExtended)
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 Table setExtendBottomRowOnSplit(boolean isExtended)
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 Table setBorderCollapse(BorderCollapsePropertyValue collapsePropertyValue)
collapsePropertyValue
- BorderCollapsePropertyValue
to be set as the border collapse type
Table
public Table setHorizontalBorderSpacing(float spacing)
public Table setVerticalBorderSpacing(float spacing)
public AccessibilityProperties getAccessibilityProperties()
IAccessibleElement
accessibility properties
. See also IAccessibleElement
.
getAccessibilityProperties
in interface IAccessibleElement
protected IRenderer makeNewRenderer()
AbstractElement
makeNewRenderer
in class AbstractElement<Table>
IRenderer
protected List<Table.RowRange> getRowGroups()
Table.RowRange
which holds the row numbers of a section of a table
Copyright © 1998–2022 iText Group NV. All rights reserved.