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 PdfName |
role |
protected AccessibilityProperties |
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)
Deprecated.
in 7.1 each column will have undefined width. Use another constructor to get predictable result.
|
Table(int numColumns, boolean largeTable)
Deprecated.
in 7.1 each column will have undefined width. Use another constructor to get predictable result.
|
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.
|
protected void |
calculateWidths()
Deprecated.
This method does nothing after implementation table column width algorithms.
|
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 .
|
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.
|
PdfName |
getRole()
Gets the element's role.
|
protected List<Table.RowRange> |
getRowGroups() |
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() |
Table |
setAutoLayout()
Set auto layout.
|
void |
setDocument(Document document)
Sets the document this element is bound to.
|
Table |
setExtendBottomRow(boolean isExtended) |
Table |
setExtendBottomRowOnSplit(boolean isExtended) |
Table |
setFixedLayout()
Set fixed layout.
|
void |
setRole(PdfName role)
Sets the element's role.
|
Table |
setSkipFirstHeader(boolean skipFirstHeader)
Skips the printing of the first header.
|
Table |
setSkipLastFooter(boolean skipLastFooter)
Skips the printing of the last footer.
|
Table |
startNewRow()
Starts new row.
|
Table |
useAllAvailableWidth()
Set Property.WIDTH = 100%.
|
getDefaultProperty, getMarginBottom, getMarginLeft, getMarginRight, getMarginTop, getPaddingBottom, getPaddingLeft, getPaddingRight, getPaddingTop, isKeepTogether, isKeepWithNext, setHeight, setKeepTogether, setKeepWithNext, setMargin, setMarginBottom, setMarginLeft, setMarginRight, setMargins, setMarginTop, setMaxHeight, setMaxWidth, setMinHeight, setMinWidth, setPadding, setPaddingBottom, setPaddingLeft, setPaddingRight, setPaddings, setPaddingTop, setRotationAngle, setRotationAngle, setSpacingRatio, setVerticalAlignment
addStyle, getChildren, getProperty, hasProperty, isEmpty, propagateArtifactRoleToChildElements, setAction, setNextRenderer, setPageNumber
deleteOwnProperty, getHeight, getOwnProperty, getSplitCharacters, getStrokeColor, getStrokeWidth, getTextRenderingMode, getWidth, hasOwnProperty, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBackgroundColor, setBaseDirection, setBold, setBorder, setBorderBottom, setBorderBottomLeftRadius, setBorderBottomRightRadius, setBorderLeft, setBorderRadius, setBorderRight, setBorderTop, setBorderTopLeftRadius, setBorderTopRightRadius, setCharacterSpacing, setDestination, setFixedPosition, setFixedPosition, setFixedPosition, setFixedPosition, setFont, setFont, setFontColor, setFontColor, setFontKerning, setFontScript, setFontSize, setHeight, setHeightPercent, setHorizontalAlignment, setHyphenation, setItalic, setLineThrough, setOpacity, setProperty, setRelativePosition, setSplitCharacters, setStrokeColor, setStrokeWidth, setTextAlignment, setTextRenderingMode, setUnderline, setUnderline, setUnderline, setUnderline, setWidth, setWidth, setWidthPercent, setWordSpacing
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
setNextRenderer
deleteOwnProperty, getDefaultProperty, getOwnProperty, getProperty, hasOwnProperty, hasProperty, setProperty
protected PdfName role
protected AccessibilityProperties 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()
@Deprecated public Table(int numColumns, boolean largeTable)
Table
with specified number of columns. Each column will get equal percent width, the final column widths depend on selected table layout. 100% table width set implicitly for backward compatibility.
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()
@Deprecated public Table(int numColumns)
Table
with specified number of columns. Each column will get equal percent width, the final column widths depend on selected table layout. 100% table width set implicitly for backward compatibility.
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 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
protected IRenderer makeNewRenderer()
makeNewRenderer
in class AbstractElement<Table>
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 PdfName getRole()
IAccessibleElement
getRole
in interface IAccessibleElement
PdfName
containing the name of the role
public void setRole(PdfName role)
IAccessibleElement
setRole
in interface IAccessibleElement
role
- the new role which the IAccessibleElement
should take
public Table setExtendBottomRow(boolean isExtended)
public Table setExtendBottomRowOnSplit(boolean isExtended)
public AccessibilityProperties getAccessibilityProperties()
IAccessibleElement
accessibility properties
.
getAccessibilityProperties
in interface IAccessibleElement
@Deprecated protected void calculateWidths()
protected List<Table.RowRange> getRowGroups()
Copyright © 1998–2018 iText Group NV. All rights reserved.