Package com.itextpdf.text.pdf
Class PdfPTable
- java.lang.Object
-
- com.itextpdf.text.pdf.PdfPTable
-
- All Implemented Interfaces:
Spaceable
,Element
,LargeElement
,IAccessibleElement
public class PdfPTable extends java.lang.Object implements LargeElement, Spaceable, IAccessibleElement
This is a table that can be put at an absolute position but can also be added to the document as the classTable
. A PdfPTableEvent can be associated to the table to do custom drawing when the table is rendered.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PdfPTable.ColumnMeasurementState
static class
PdfPTable.FittingRows
-
Field Summary
Fields Modifier and Type Field Description protected float[]
absoluteWidths
protected java.util.HashMap<PdfName,PdfObject>
accessibleAttributes
static int
BACKGROUNDCANVAS
The index of the duplicatePdfContentByte
where the background will be drawn.static int
BASECANVAS
The index of the originalPdfcontentByte
.private PdfPTableBody
body
protected boolean
complete
Indicates if the PdfPTable is complete once added to the document.protected int
currentColIdx
The current column index.protected PdfPCell[]
currentRow
protected PdfPCell
defaultCell
private boolean[]
extendLastRow
Holds value of property extendLastRow.private PdfPTableFooter
footer
private int
footerRows
Holds value of property footerRows.private PdfPTableHeader
header
protected int
headerRows
Holds value of property headerRows.private boolean
headersInEvent
Holds value of property headersInEvent.private int
horizontalAlignment
Holds value of property horizontalAlignment.protected AccessibleElementId
id
protected boolean
isColspan
private boolean
keepTogether
Defines if the table should be kept on one page if possiblestatic int
LINECANVAS
The index of the duplicatePdfContentByte
where the border lines will be drawn.private boolean
lockedWidth
Holds value of property lockedWidth.private Logger
LOGGER
protected boolean
loopCheck
private int
numberOfWrittenRows
protected float
paddingTop
protected float[]
relativeWidths
protected PdfName
role
protected boolean
rowCompleted
Keeps track of the completeness of the current row.protected java.util.ArrayList<PdfPRow>
rows
protected boolean
rowsNotChecked
protected int
runDirection
private boolean
skipFirstHeader
Holds value of property skipFirstHeader.private boolean
skipLastFooter
Holds value of property skipLastFooter.protected float
spacingAfter
The spacing after the table.protected float
spacingBefore
The spacing before the table.private boolean
splitLate
Holds value of property splitLate.private boolean
splitRows
Holds value of property splitRows.protected PdfPTableEvent
tableEvent
static int
TEXTCANVAS
The index of the duplicatePdfContentByte
where the text will be drawn.protected float
totalHeight
protected float
totalWidth
protected float
widthPercentage
Holds value of property widthPercentage.-
Fields inherited from interface com.itextpdf.text.Element
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, BODY, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CHAPTER, CHUNK, CREATIONDATE, CREATOR, DIV, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LANGUAGE, LIST, LISTITEM, MARKED, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, SECTION, SUBJECT, TITLE, WRITABLE_DIRECT, YMARK
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
PdfPTable()
PdfPTable(float[] relativeWidths)
Constructs aPdfPTable
with the relative column widths.PdfPTable(int numColumns)
Constructs aPdfPTable
withnumColumns
columns.PdfPTable(PdfPTable table)
Constructs a copy of aPdfPTable
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addCell(Image image)
Adds an Image as Cell.PdfPCell
addCell(PdfPCell cell)
Adds a cell element.void
addCell(PdfPTable table)
Adds a nested table.void
addCell(Phrase phrase)
Adds a cell element.void
addCell(java.lang.String text)
Adds a cell element.(package private) void
addNumberOfRowsWritten(int numberOfWrittenRows)
Adds the number of written rows to the counter.protected PdfPRow
adjustCellsInRow(int start, int end)
Calculates the extra height needed in a row because of rowspans.static PdfContentByte[]
beginWritingRows(PdfContentByte canvas)
Gets and initializes the 4 layers where the table is written to.float
calculateHeights()
Calculates the heights of the table.protected void
calculateWidths()
(package private) PdfPCell
cellAt(int row, int col)
Added by timmo3.private PdfPTableBody
closeTableBlock(PdfPTableBody block, PdfContentByte canvas)
void
completeRow()
Completes the current row with the default cell.protected void
copyFormat(PdfPTable sourceTable)
Copies the format of the sourceTable without copying the content.void
deleteBodyRows()
Removes all of the rows except headersboolean
deleteLastRow()
Deletes the last row in the table.boolean
deleteRow(int rowNumber)
Deletes a row from the table.static void
endWritingRows(PdfContentByte[] canvases)
Finishes writing the table.void
flushContent()
Flushes the content that has been added.float[]
getAbsoluteWidths()
Gets the absolute sizes of each column width.PdfObject
getAccessibleAttribute(PdfName key)
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).java.util.HashMap<PdfName,PdfObject>
getAccessibleAttributes()
Gets all the properties of accessible element.PdfPTableBody
getBody()
int
getCellStartRowIndex(int rowIdx, int colIdx)
Gets row index where cell overlapping (rowIdx, colIdx) startsjava.util.List<Chunk>
getChunks()
Gets all the chunks in this element.PdfPCell
getDefaultCell()
Gets the defaultPdfPCell
that will be used as reference for all theaddCell
methods exceptaddCell(PdfPCell)
.(package private) float[][]
getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders)
PdfPTable.FittingRows
getFittingRows(float availableHeight, int startIdx)
Determine which rows fit on the page, respecting isSplitLate().PdfPTableFooter
getFooter()
float
getFooterHeight()
Gets the height of the rows that constitute the footer as defined bysetFooterRows()
.int
getFooterRows()
Gets the number of rows in the footer.PdfPTableHeader
getHeader()
float
getHeaderHeight()
Gets the height of the rows that constitute the header as defined bysetHeaderRows()
.int
getHeaderRows()
Gets the number of the rows that constitute the header.int
getHorizontalAlignment()
Gets the horizontal alignment of the table relative to the page.AccessibleElementId
getId()
boolean
getKeepTogether()
Getter for property keepTogetherint
getLastCompletedRowIndex()
Returns the index of the last completed row.int
getNumberOfColumns()
Returns the number of columns.float
getPaddingTop()
PdfName
getRole()
Gets the role of the accessible element.PdfPRow
getRow(int idx)
Gets a row with a given index.float
getRowHeight(int idx)
Gets the height of a particular row.protected float
getRowHeight(int idx, boolean firsttime)
Gets the height of a particular row.java.util.ArrayList<PdfPRow>
getRows()
Gets an arraylist with all the rows in the table.java.util.ArrayList<PdfPRow>
getRows(int start, int end)
Gets an arraylist with a selection of rows.float
getRowspanHeight(int rowIndex, int cellIndex)
Gets the maximum height of a cell in a particular row (will only be different from getRowHeight is one of the cells in the row has a rowspan > 1).int
getRunDirection()
Returns the run direction of the contents in the table.float
getSpacingAfter()
Gets the spacing after.float
getSpacingBefore()
Gets the spacing before.java.lang.String
getSummary()
PdfPTableEvent
getTableEvent()
Gets the table event for this page.float
getTotalHeight()
Gets the total height of the table.float
getTotalWidth()
Gets the full width of the table.float
getWidthPercentage()
Gets the width percentage that the table will occupy in the page.boolean
hasRowspan(int rowIdx)
Checks if a cell in a row has a rowspan greater than 1.void
init()
boolean
isComplete()
Indicates if the element is complete or not.boolean
isContent()
Checks if this element is a content object.boolean
isExtendLastRow()
Gets the value of the last row extension.boolean
isExtendLastRow(boolean newPageFollows)
Gets the value of the last row extension, taking into account if the final row is reached or not.boolean
isHeadersInEvent()
Gets the header status inclusion in PdfPTableEvent.boolean
isInline()
boolean
isLockedWidth()
Getter for property lockedWidth.boolean
isLoopCheck()
boolean
isNestable()
Checks if this element is nestable.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")boolean
isSplitLate()
Gets the property splitLate.boolean
isSplitRows()
Gets the split value.void
keepRowsTogether(int start)
Defines a range of rows (from the parameter to the last row) that should not allow a page break (if possible).void
keepRowsTogether(int[] rows)
Defines which rows should not allow a page break (if possible).void
keepRowsTogether(int start, int end)
Defines a range of rows that should not allow a page break (if possible).void
normalizeHeadersFooters()
Makes sure the footers value is lower than the headers value.private PdfPTableBody
openTableBlock(PdfPTableBody block, PdfContentByte canvas)
boolean
process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.void
resetColumnCount(int newColCount)
Changes the number of columns.(package private) boolean
rowSpanAbove(int currRow, int currCol)
Checks if there are rows above belonging to a rowspan.void
setAccessibleAttribute(PdfName key, PdfObject value)
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).void
setBreakPoints(int... breakPoints)
Defines where the table may be broken (if necessary).void
setComplete(boolean complete)
If you invoke setComplete(false), you indicate that the content of the object isn't complete yet; it can be added to the document partially, but more will follow.void
setExtendLastRow(boolean extendLastRows)
When set the last row on every page will be extended to fill all the remaining space to the bottom boundary.void
setExtendLastRow(boolean extendLastRows, boolean extendFinalRow)
When set the last row on every page will be extended to fill all the remaining space to the bottom boundary; except maybe the final row.void
setFooterRows(int footerRows)
Sets the number of rows to be used for the footer.void
setHeaderRows(int headerRows)
Sets the number of the top rows that constitute the header.void
setHeadersInEvent(boolean headersInEvent)
When set the PdfPTableEvent will include the headers.void
setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal alignment of the table relative to the page.void
setId(AccessibleElementId id)
void
setKeepTogether(boolean keepTogether)
If true the table will be kept on one page if it fits, by forcing a new page if it doesn't fit on the current page.void
setLockedWidth(boolean lockedWidth)
Uses the value insetTotalWidth()
inDocument.add()
.void
setLoopCheck(boolean loopCheck)
void
setPaddingTop(float paddingTop)
void
setRole(PdfName role)
Sets the role of the accessiblee element.void
setRunDirection(int runDirection)
Sets the run direction of the contents of the table.void
setSkipFirstHeader(boolean skipFirstHeader)
Skips the printing of the first header.void
setSkipLastFooter(boolean skipLastFooter)
Skips the printing of the last footer.void
setSpacingAfter(float spacing)
Sets the spacing after this table.void
setSpacingBefore(float spacing)
Sets the spacing before this table.void
setSplitLate(boolean splitLate)
If true the row will only split if it's the first one in an empty page.void
setSplitRows(boolean splitRows)
When set the rows that won't fit in the page will be split.void
setSummary(java.lang.String summary)
void
setTableEvent(PdfPTableEvent event)
Sets the table event for this table.void
setTotalWidth(float totalWidth)
Sets the full width of the table.void
setTotalWidth(float[] columnWidth)
Sets the full width of the table from the absolute column width.void
setWidthPercentage(float widthPercentage)
Sets the width percentage that the table will occupy in the page.void
setWidthPercentage(float[] columnWidth, Rectangle pageSize)
Sets the percentage width of the table from the absolute column width.void
setWidths(float[] relativeWidths)
Sets the relative widths of the table.void
setWidths(int[] relativeWidths)
Sets the relative widths of the table.static PdfPTable
shallowCopy(PdfPTable table)
Makes a shallow copy of a table (format without content).int
size()
Gets the number of rows in this table.private void
skipColsWithRowspanAbove()
When updating the row index, cells with rowspan should be taken into account.float
spacingAfter()
Gets the spacing after this table.float
spacingBefore()
Gets the spacing before this table.int
type()
Gets the type of the text element.float
writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
Writes the selected rows to the document.float
writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
Writes the selected rows to the document.float
writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
Writes the selected rows and columns to the document.float
writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
Writes the selected rows and columns to the document.float
writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases, boolean reusable)
Writes the selected rows and columns to the document.float
writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas, boolean reusable)
Writes the selected rows and columns to the document.
-
-
-
Field Detail
-
LOGGER
private final Logger LOGGER
-
BASECANVAS
public static final int BASECANVAS
The index of the originalPdfcontentByte
.- See Also:
- Constant Field Values
-
BACKGROUNDCANVAS
public static final int BACKGROUNDCANVAS
The index of the duplicatePdfContentByte
where the background will be drawn.- See Also:
- Constant Field Values
-
LINECANVAS
public static final int LINECANVAS
The index of the duplicatePdfContentByte
where the border lines will be drawn.- See Also:
- Constant Field Values
-
TEXTCANVAS
public static final int TEXTCANVAS
The index of the duplicatePdfContentByte
where the text will be drawn.- See Also:
- Constant Field Values
-
rows
protected java.util.ArrayList<PdfPRow> rows
-
totalHeight
protected float totalHeight
-
currentRow
protected PdfPCell[] currentRow
-
currentColIdx
protected int currentColIdx
The current column index.- Since:
- 5.1.0 renamed from currentRowIdx
-
defaultCell
protected PdfPCell defaultCell
-
totalWidth
protected float totalWidth
-
relativeWidths
protected float[] relativeWidths
-
absoluteWidths
protected float[] absoluteWidths
-
tableEvent
protected PdfPTableEvent tableEvent
-
headerRows
protected int headerRows
Holds value of property headerRows.
-
widthPercentage
protected float widthPercentage
Holds value of property widthPercentage.
-
horizontalAlignment
private int horizontalAlignment
Holds value of property horizontalAlignment.
-
skipFirstHeader
private boolean skipFirstHeader
Holds value of property skipFirstHeader.
-
skipLastFooter
private boolean skipLastFooter
Holds value of property skipLastFooter.- Since:
- 2.1.6
-
isColspan
protected boolean isColspan
-
runDirection
protected int runDirection
-
lockedWidth
private boolean lockedWidth
Holds value of property lockedWidth.
-
splitRows
private boolean splitRows
Holds value of property splitRows.
-
spacingBefore
protected float spacingBefore
The spacing before the table.
-
spacingAfter
protected float spacingAfter
The spacing after the table.
-
paddingTop
protected float paddingTop
-
extendLastRow
private boolean[] extendLastRow
Holds value of property extendLastRow.
-
headersInEvent
private boolean headersInEvent
Holds value of property headersInEvent.
-
splitLate
private boolean splitLate
Holds value of property splitLate.
-
keepTogether
private boolean keepTogether
Defines if the table should be kept on one page if possible
-
complete
protected boolean complete
Indicates if the PdfPTable is complete once added to the document.- Since:
- iText 2.0.8
-
footerRows
private int footerRows
Holds value of property footerRows.
-
rowCompleted
protected boolean rowCompleted
Keeps track of the completeness of the current row.- Since:
- 2.1.6
-
loopCheck
protected boolean loopCheck
-
rowsNotChecked
protected boolean rowsNotChecked
-
role
protected PdfName role
-
id
protected AccessibleElementId id
-
header
private PdfPTableHeader header
-
body
private PdfPTableBody body
-
footer
private PdfPTableFooter footer
-
numberOfWrittenRows
private int numberOfWrittenRows
-
-
Constructor Detail
-
PdfPTable
protected PdfPTable()
-
PdfPTable
public PdfPTable(float[] relativeWidths)
Constructs aPdfPTable
with the relative column widths.- Parameters:
relativeWidths
- the relative column widths
-
PdfPTable
public PdfPTable(int numColumns)
Constructs aPdfPTable
withnumColumns
columns.- Parameters:
numColumns
- the number of columns
-
PdfPTable
public PdfPTable(PdfPTable table)
Constructs a copy of aPdfPTable
.- Parameters:
table
- thePdfPTable
to be copied
-
-
Method Detail
-
init
public void init()
-
shallowCopy
public static PdfPTable shallowCopy(PdfPTable table)
Makes a shallow copy of a table (format without content).- Parameters:
table
-- Returns:
- a shallow copy of the table
-
copyFormat
protected void copyFormat(PdfPTable sourceTable)
Copies the format of the sourceTable without copying the content.- Parameters:
sourceTable
-- Since:
- 2.1.6 private is now protected
-
setWidths
public void setWidths(float[] relativeWidths) throws DocumentException
Sets the relative widths of the table.- Parameters:
relativeWidths
- the relative widths of the table.- Throws:
DocumentException
- if the number of widths is different than the number of columns
-
setWidths
public void setWidths(int[] relativeWidths) throws DocumentException
Sets the relative widths of the table.- Parameters:
relativeWidths
- the relative widths of the table.- Throws:
DocumentException
- if the number of widths is different than the number of columns
-
calculateWidths
protected void calculateWidths()
- Since:
- 2.1.6 private is now protected
-
setTotalWidth
public void setTotalWidth(float totalWidth)
Sets the full width of the table.- Parameters:
totalWidth
- the full width of the table.
-
setTotalWidth
public void setTotalWidth(float[] columnWidth) throws DocumentException
Sets the full width of the table from the absolute column width.- Parameters:
columnWidth
- the absolute width of each column- Throws:
DocumentException
- if the number of widths is different than the number of columns
-
setWidthPercentage
public void setWidthPercentage(float[] columnWidth, Rectangle pageSize) throws DocumentException
Sets the percentage width of the table from the absolute column width. Warning: Don't use this with setLockedWidth(true). These two settings don't mix.- Parameters:
columnWidth
- the absolute width of each columnpageSize
- the page size- Throws:
DocumentException
-
getTotalWidth
public float getTotalWidth()
Gets the full width of the table.- Returns:
- the full width of the table
-
calculateHeights
public float calculateHeights()
Calculates the heights of the table.- Returns:
- the total height of the table. Note that it will be 0 if you didn't specify the width of the table with setTotalWidth(). and made it public
-
resetColumnCount
public void resetColumnCount(int newColCount)
Changes the number of columns. Any existing rows will be deleted.- Parameters:
newColCount
- the new number of columns- Since:
- 5.0.2
-
getDefaultCell
public PdfPCell getDefaultCell()
Gets the defaultPdfPCell
that will be used as reference for all theaddCell
methods exceptaddCell(PdfPCell)
.- Returns:
- default
PdfPCell
-
addCell
public PdfPCell addCell(PdfPCell cell)
Adds a cell element.- Parameters:
cell
- the cell element
-
skipColsWithRowspanAbove
private void skipColsWithRowspanAbove()
When updating the row index, cells with rowspan should be taken into account. This is what happens in this method.- Since:
- 2.1.6
-
cellAt
PdfPCell cellAt(int row, int col)
Added by timmo3. This will return the correct cell taking it's cellspan into account- Parameters:
row
- the row indexcol
- the column index- Returns:
- PdfPCell at the given row and position or null otherwise
-
rowSpanAbove
boolean rowSpanAbove(int currRow, int currCol)
Checks if there are rows above belonging to a rowspan.- Parameters:
currRow
- the current row to checkcurrCol
- the current column to check- Returns:
- true if there's a cell above that belongs to a rowspan
- Since:
- 2.1.6
-
addCell
public void addCell(java.lang.String text)
Adds a cell element.- Parameters:
text
- the text for the cell
-
addCell
public void addCell(PdfPTable table)
Adds a nested table.- Parameters:
table
- the table to be added to the cell
-
addCell
public void addCell(Image image)
Adds an Image as Cell.- Parameters:
image
- theImage
to add to the table. This image will fit in the cell
-
addCell
public void addCell(Phrase phrase)
Adds a cell element.- Parameters:
phrase
- thePhrase
to be added to the cell
-
writeSelectedRows
public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
Writes the selected rows to the document.canvases
is obtained frombeginWritingRows()
.- Parameters:
rowStart
- the first row to be written, zero indexrowEnd
- the last row to be written + 1. If it is -1 all the rows to the end are writtenxPos
- the x write coordinateyPos
- the y write coordinatecanvases
- an array of 4PdfContentByte
obtained frombeginWrittingRows()
- Returns:
- the y coordinate position of the bottom of the last row
- See Also:
beginWritingRows(com.itextpdf.text.pdf.PdfContentByte)
-
writeSelectedRows
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
Writes the selected rows and columns to the document. This method does not clip the columns; this is only important if there are columns with colspan at boundaries.canvases
is obtained frombeginWritingRows()
. The table event is only fired for complete rows.- Parameters:
colStart
- the first column to be written, zero indexcolEnd
- the last column to be written + 1. If it is -1 all the columns to the end are writtenrowStart
- the first row to be written, zero indexrowEnd
- the last row to be written + 1. If it is -1 all the rows to the end are writtenxPos
- the x write coordinateyPos
- the y write coordinatecanvases
- an array of 4PdfContentByte
obtained frombeginWritingRows()
- Returns:
- the y coordinate position of the bottom of the last row
- See Also:
beginWritingRows(com.itextpdf.text.pdf.PdfContentByte)
-
writeSelectedRows
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases, boolean reusable)
Writes the selected rows and columns to the document. This method does not clip the columns; this is only important if there are columns with colspan at boundaries.canvases
is obtained frombeginWritingRows()
. The table event is only fired for complete rows.- Parameters:
colStart
- the first column to be written, zero indexcolEnd
- the last column to be written + 1. If it is -1 all the columns to the end are writtenrowStart
- the first row to be written, zero indexrowEnd
- the last row to be written + 1. If it is -1 all the rows to the end are writtenxPos
- the x write coordinateyPos
- the y write coordinatecanvases
- an array of 4PdfContentByte
obtained frombeginWritingRows()
reusable
- if set to false, the content in the cells is "consumed"; if true, you can reuse the cells, the row, the parent table as many times you want.- Returns:
- the y coordinate position of the bottom of the last row
- Since:
- 5.1.0 added the reusable parameter
- See Also:
beginWritingRows(com.itextpdf.text.pdf.PdfContentByte)
-
openTableBlock
private PdfPTableBody openTableBlock(PdfPTableBody block, PdfContentByte canvas)
-
closeTableBlock
private PdfPTableBody closeTableBlock(PdfPTableBody block, PdfContentByte canvas)
-
writeSelectedRows
public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
Writes the selected rows to the document.- Parameters:
rowStart
- the first row to be written, zero indexrowEnd
- the last row to be written + 1. If it is -1 all the rows to the end are writtenxPos
- the x write coordinateyPos
- the y write coordinatecanvas
- thePdfContentByte
where the rows will be written to- Returns:
- the y coordinate position of the bottom of the last row
-
writeSelectedRows
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
Writes the selected rows and columns to the document. This method clips the columns; this is only important if there are columns with colspan at boundaries. The table event is only fired for complete rows.- Parameters:
colStart
- the first column to be written, zero indexcolEnd
- the last column to be written + 1. If it is -1 all the columns to the end are writtenrowStart
- the first row to be written, zero indexrowEnd
- the last row to be written + 1. If it is -1 all the rows to the end are writtenxPos
- the x write coordinateyPos
- the y write coordinatecanvas
- thePdfContentByte
where the rows will be written to- Returns:
- the y coordinate position of the bottom of the last row
-
writeSelectedRows
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas, boolean reusable)
Writes the selected rows and columns to the document. This method clips the columns; this is only important if there are columns with colspan at boundaries. The table event is only fired for complete rows.- Parameters:
colStart
- the first column to be written, zero indexcolEnd
- the last column to be written + 1. If it is -1 all the columns to the end are writtenrowStart
- the first row to be written, zero indexrowEnd
- the last row to be written + 1. If it is -1 all the rows to the end are writtenxPos
- the x write coordinateyPos
- the y write coordinatecanvas
- thePdfContentByte
where the rows will be written toreusable
- if set to false, the content in the cells is "consumed"; if true, you can reuse the cells, the row, the parent table as many times you want.- Returns:
- the y coordinate position of the bottom of the last row
- Since:
- 5.1.0 added the reusable parameter
-
beginWritingRows
public static PdfContentByte[] beginWritingRows(PdfContentByte canvas)
Gets and initializes the 4 layers where the table is written to. The text or graphics are added to one of the 4PdfContentByte
returned with the following order:PdfPtable.BASECANVAS
- the originalPdfContentByte
. Anything placed here will be under the table.PdfPtable.BACKGROUNDCANVAS
- the layer where the background goes to.PdfPtable.LINECANVAS
- the layer where the lines go to.PdfPtable.TEXTCANVAS
- the layer where the text go to. Anything placed here will be over the table.
The layers are placed in sequence on top of each other.
- Parameters:
canvas
- thePdfContentByte
where the rows will be written to- Returns:
- an array of 4
PdfContentByte
- See Also:
writeSelectedRows(int, int, float, float, PdfContentByte[])
-
endWritingRows
public static void endWritingRows(PdfContentByte[] canvases)
Finishes writing the table.- Parameters:
canvases
- the array returned bybeginWritingRows()
-
size
public int size()
Gets the number of rows in this table.- Returns:
- the number of rows in this table
-
getTotalHeight
public float getTotalHeight()
Gets the total height of the table.- Returns:
- the total height of the table
-
getRowHeight
public float getRowHeight(int idx)
Gets the height of a particular row.- Parameters:
idx
- the row index (starts at 0)- Returns:
- the height of a particular row
-
getRowHeight
protected float getRowHeight(int idx, boolean firsttime)
Gets the height of a particular row.- Parameters:
idx
- the row index (starts at 0)firsttime
- is this the first time the row heigh is calculated?- Returns:
- the height of a particular row
- Since:
- 5.0.0
-
getRowspanHeight
public float getRowspanHeight(int rowIndex, int cellIndex)
Gets the maximum height of a cell in a particular row (will only be different from getRowHeight is one of the cells in the row has a rowspan > 1).- Parameters:
rowIndex
- the row indexcellIndex
- the cell index- Returns:
- the height of a particular row including rowspan
- Since:
- 2.1.6
-
hasRowspan
public boolean hasRowspan(int rowIdx)
Checks if a cell in a row has a rowspan greater than 1.- Since:
- 5.1.0
-
normalizeHeadersFooters
public void normalizeHeadersFooters()
Makes sure the footers value is lower than the headers value.- Since:
- 5.0.1
-
getHeaderHeight
public float getHeaderHeight()
Gets the height of the rows that constitute the header as defined bysetHeaderRows()
.- Returns:
- the height of the rows that constitute the header and footer
-
getFooterHeight
public float getFooterHeight()
Gets the height of the rows that constitute the footer as defined bysetFooterRows()
.- Returns:
- the height of the rows that constitute the footer
- Since:
- 2.1.1
-
deleteRow
public boolean deleteRow(int rowNumber)
Deletes a row from the table.- Parameters:
rowNumber
- the row to be deleted- Returns:
true
if the row was deleted
-
deleteLastRow
public boolean deleteLastRow()
Deletes the last row in the table.- Returns:
true
if the last row was deleted
-
deleteBodyRows
public void deleteBodyRows()
Removes all of the rows except headers
-
getNumberOfColumns
public int getNumberOfColumns()
Returns the number of columns.- Returns:
- the number of columns.
- Since:
- 2.1.1
-
getHeaderRows
public int getHeaderRows()
Gets the number of the rows that constitute the header.- Returns:
- the number of the rows that constitute the header
-
setHeaderRows
public void setHeaderRows(int headerRows)
Sets the number of the top rows that constitute the header. This header has only meaning if the table is added toDocument
and the table crosses pages.- Parameters:
headerRows
- the number of the top rows that constitute the header
-
getChunks
public java.util.List<Chunk> getChunks()
Gets all the chunks in this element.
-
type
public int type()
Gets the type of the text element.
-
isContent
public boolean isContent()
Description copied from interface:Element
Checks if this element is a content object. If not, it's a metadata object.- Specified by:
isContent
in interfaceElement
- Returns:
- true if this is a 'content' element; false if this is a 'metadata' element
- Since:
- iText 2.0.8
- See Also:
Element.isContent()
-
isNestable
public boolean isNestable()
Description copied from interface:Element
Checks if this element is nestable.- Specified by:
isNestable
in interfaceElement
- Returns:
- true if this element can be nested inside other elements.
- Since:
- iText 2.0.8
- See Also:
Element.isNestable()
-
process
public boolean process(ElementListener listener)
Processes the element by adding it (or the different parts) to anElementListener
.
-
getSummary
public java.lang.String getSummary()
-
setSummary
public void setSummary(java.lang.String summary)
-
getWidthPercentage
public float getWidthPercentage()
Gets the width percentage that the table will occupy in the page.- Returns:
- the width percentage that the table will occupy in the page
-
setWidthPercentage
public void setWidthPercentage(float widthPercentage)
Sets the width percentage that the table will occupy in the page.- Parameters:
widthPercentage
- the width percentage that the table will occupy in the page
-
getHorizontalAlignment
public int getHorizontalAlignment()
Gets the horizontal alignment of the table relative to the page.- Returns:
- the horizontal alignment of the table relative to the page
-
setHorizontalAlignment
public void setHorizontalAlignment(int horizontalAlignment)
Sets the horizontal alignment of the table relative to the page. It only has meaning if the width percentage is less than 100%.- Parameters:
horizontalAlignment
- the horizontal alignment of the table relative to the page
-
getRow
public PdfPRow getRow(int idx)
Gets a row with a given index.- Parameters:
idx
-- Returns:
- the row at position idx
-
getRows
public java.util.ArrayList<PdfPRow> getRows()
Gets an arraylist with all the rows in the table.- Returns:
- an arraylist
-
getLastCompletedRowIndex
public int getLastCompletedRowIndex()
Returns the index of the last completed row.- Returns:
- the index of a row
-
setBreakPoints
public void setBreakPoints(int... breakPoints)
Defines where the table may be broken (if necessary).- Parameters:
breakPoints
- int[]- Throws:
java.lang.IndexOutOfBoundsException
- if a row index is passed that is out of bounds
-
keepRowsTogether
public void keepRowsTogether(int[] rows)
Defines which rows should not allow a page break (if possible).- Parameters:
rows
- int[]- Throws:
java.lang.IndexOutOfBoundsException
- if a row index is passed that is out of bounds
-
keepRowsTogether
public void keepRowsTogether(int start, int end)
Defines a range of rows that should not allow a page break (if possible).- Parameters:
start
- intend
- int- Throws:
java.lang.IndexOutOfBoundsException
- if a row index is passed that is out of bounds
-
keepRowsTogether
public void keepRowsTogether(int start)
Defines a range of rows (from the parameter to the last row) that should not allow a page break (if possible). The equivalent of callingkeepRowsTogether(start, rows.size()
.- Parameters:
start
- int- Throws:
java.lang.IndexOutOfBoundsException
- if a row index is passed that is out of bounds
-
getRows
public java.util.ArrayList<PdfPRow> getRows(int start, int end)
Gets an arraylist with a selection of rows.- Parameters:
start
- the first row in the selectionend
- the first row that isn't part of the selection- Returns:
- a selection of rows
- Since:
- 2.1.6
-
adjustCellsInRow
protected PdfPRow adjustCellsInRow(int start, int end)
Calculates the extra height needed in a row because of rowspans.- Parameters:
start
- the index of the start row (the one to adjust)end
- the index of the end row on the page- Since:
- 2.1.6
-
setTableEvent
public void setTableEvent(PdfPTableEvent event)
Sets the table event for this table.- Parameters:
event
- the table event for this table
-
getTableEvent
public PdfPTableEvent getTableEvent()
Gets the table event for this page.- Returns:
- the table event for this page
-
getAbsoluteWidths
public float[] getAbsoluteWidths()
Gets the absolute sizes of each column width.- Returns:
- he absolute sizes of each column width
-
getEventWidths
float[][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders)
-
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.
-
isSkipLastFooter
public boolean isSkipLastFooter()
Tells you if the last footer needs to be skipped (for instance if the footer says "continued on the next page")- Returns:
- Value of property skipLastFooter.
- Since:
- 2.1.6
-
setSkipFirstHeader
public void setSkipFirstHeader(boolean skipFirstHeader)
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.
-
setSkipLastFooter
public void setSkipLastFooter(boolean skipLastFooter)
Skips the printing of the last footer. Used when printing tables in succession belonging to the same printed table aspect.- Parameters:
skipLastFooter
- New value of property skipLastFooter.- Since:
- 2.1.6
-
setRunDirection
public void setRunDirection(int runDirection)
Sets the run direction of the contents of the table.- Parameters:
runDirection
- One of the following values: PdfWriter.RUN_DIRECTION_DEFAULT, PdfWriter.RUN_DIRECTION_NO_BIDI, PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL.
-
getRunDirection
public int getRunDirection()
Returns the run direction of the contents in the table.- Returns:
- One of the following values: PdfWriter.RUN_DIRECTION_DEFAULT, PdfWriter.RUN_DIRECTION_NO_BIDI, PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL.
-
isLockedWidth
public boolean isLockedWidth()
Getter for property lockedWidth.- Returns:
- Value of property lockedWidth.
-
setLockedWidth
public void setLockedWidth(boolean lockedWidth)
Uses the value insetTotalWidth()
inDocument.add()
.- Parameters:
lockedWidth
-true
to use the value insetTotalWidth()
inDocument.add()
-
isSplitRows
public boolean isSplitRows()
Gets the split value.- Returns:
- true to split; false otherwise
-
setSplitRows
public void setSplitRows(boolean splitRows)
When set the rows that won't fit in the page will be split. Note that it takes at least twice the memory to handle a split table row than a normal table.true
by default.- Parameters:
splitRows
- true to split; false otherwise
-
setSpacingBefore
public void setSpacingBefore(float spacing)
Sets the spacing before this table.- Specified by:
setSpacingBefore
in interfaceSpaceable
- Parameters:
spacing
- the new spacing
-
setSpacingAfter
public void setSpacingAfter(float spacing)
Sets the spacing after this table.- Specified by:
setSpacingAfter
in interfaceSpaceable
- Parameters:
spacing
- the new spacing
-
spacingBefore
public float spacingBefore()
Gets the spacing before this table.- Returns:
- the spacing
-
spacingAfter
public float spacingAfter()
Gets the spacing after this table.- Returns:
- the spacing
-
getPaddingTop
public float getPaddingTop()
- Specified by:
getPaddingTop
in interfaceSpaceable
-
setPaddingTop
public void setPaddingTop(float paddingTop)
- Specified by:
setPaddingTop
in interfaceSpaceable
-
isExtendLastRow
public boolean isExtendLastRow()
Gets the value of the last row extension.- Returns:
- true if the last row will extend; false otherwise
-
setExtendLastRow
public void setExtendLastRow(boolean extendLastRows)
When set the last row on every page will be extended to fill all the remaining space to the bottom boundary.- Parameters:
extendLastRows
- true to extend the last row; false otherwise
-
setExtendLastRow
public void setExtendLastRow(boolean extendLastRows, boolean extendFinalRow)
When set the last row on every page will be extended to fill all the remaining space to the bottom boundary; except maybe the final row.- Parameters:
extendLastRows
- true to extend the last row on each page; false otherwiseextendFinalRow
- false if you don't want to extend the final row of the complete table- Since:
- iText 5.0.0
-
isExtendLastRow
public boolean isExtendLastRow(boolean newPageFollows)
Gets the value of the last row extension, taking into account if the final row is reached or not.- Returns:
- true if the last row will extend; false otherwise
- Since:
- iText 5.0.0
-
isHeadersInEvent
public boolean isHeadersInEvent()
Gets the header status inclusion in PdfPTableEvent.- Returns:
- true if the headers are included; false otherwise
-
setHeadersInEvent
public void setHeadersInEvent(boolean headersInEvent)
When set the PdfPTableEvent will include the headers.- Parameters:
headersInEvent
- true to include the headers; false otherwise
-
isSplitLate
public boolean isSplitLate()
Gets the property splitLate.- Returns:
- the property splitLate
-
setSplitLate
public void setSplitLate(boolean splitLate)
If true the row will only split if it's the first one in an empty page. It's true by default. It's only meaningful if setSplitRows(true).- Parameters:
splitLate
- the property value
-
setKeepTogether
public void setKeepTogether(boolean keepTogether)
If true the table will be kept on one page if it fits, by forcing a new page if it doesn't fit on the current page. The default is to split the table over multiple pages.- Parameters:
keepTogether
- whether to try to keep the table on one page
-
getKeepTogether
public boolean getKeepTogether()
Getter for property keepTogether- Returns:
- true if it is tried to keep the table on one page; false otherwise
-
getFooterRows
public int getFooterRows()
Gets the number of rows in the footer.- Returns:
- the number of rows in the footer
-
setFooterRows
public void setFooterRows(int footerRows)
Sets the number of rows to be used for the footer. The number of footer rows are subtracted from the header rows. For example, for a table with two header rows and one footer row the code would be:table.setHeaderRows(3); table.setFooterRows(1);
Row 0 and 1 will be the header rows and row 2 will be the footer row.- Parameters:
footerRows
- the number of rows to be used for the footer
-
completeRow
public void completeRow()
Completes the current row with the default cell. An incomplete row will be dropped but calling this method will make sure that it will be present in the table.
-
flushContent
public void flushContent()
Description copied from interface:LargeElement
Flushes the content that has been added.- Specified by:
flushContent
in interfaceLargeElement
- Since:
- iText 2.0.8
- See Also:
LargeElement.flushContent()
-
addNumberOfRowsWritten
void addNumberOfRowsWritten(int numberOfWrittenRows)
Adds the number of written rows to the counter.- Parameters:
numberOfWrittenRows
- number of newly written rows- Since:
- 5.5.4
-
isComplete
public boolean isComplete()
Description copied from interface:LargeElement
Indicates if the element is complete or not.- Specified by:
isComplete
in interfaceLargeElement
- Returns:
- indicates if the element is complete according to the user.
- Since:
- iText 2.0.8
- See Also:
LargeElement.isComplete()
-
setComplete
public void setComplete(boolean complete)
Description copied from interface:LargeElement
If you invoke setComplete(false), you indicate that the content of the object isn't complete yet; it can be added to the document partially, but more will follow. If you invoke setComplete(true), you indicate that you won't add any more data to the object.- Specified by:
setComplete
in interfaceLargeElement
- Parameters:
complete
- false if you'll be adding more data after adding the object to the document.- Since:
- iText 2.0.8
- See Also:
LargeElement.setComplete(boolean)
-
getSpacingBefore
public float getSpacingBefore()
Description copied from interface:Spaceable
Gets the spacing before.- Specified by:
getSpacingBefore
in interfaceSpaceable
- Returns:
- the spacing
-
getSpacingAfter
public float getSpacingAfter()
Description copied from interface:Spaceable
Gets the spacing after.- Specified by:
getSpacingAfter
in interfaceSpaceable
- Returns:
- the spacing
-
isLoopCheck
public boolean isLoopCheck()
-
setLoopCheck
public void setLoopCheck(boolean loopCheck)
-
getAccessibleAttribute
public PdfObject getAccessibleAttribute(PdfName key)
Description copied from interface:IAccessibleElement
Get the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
getAccessibleAttribute
in interfaceIAccessibleElement
- Returns:
-
setAccessibleAttribute
public void setAccessibleAttribute(PdfName key, PdfObject value)
Description copied from interface:IAccessibleElement
Set the attribute of accessible element (everything inA
dictionary +Lang
,Alt
,ActualText
,E
).- Specified by:
setAccessibleAttribute
in interfaceIAccessibleElement
-
getAccessibleAttributes
public java.util.HashMap<PdfName,PdfObject> getAccessibleAttributes()
Description copied from interface:IAccessibleElement
Gets all the properties of accessible element.- Specified by:
getAccessibleAttributes
in interfaceIAccessibleElement
- Returns:
-
getRole
public PdfName getRole()
Description copied from interface:IAccessibleElement
Gets the role of the accessible element.- Specified by:
getRole
in interfaceIAccessibleElement
- Returns:
-
setRole
public void setRole(PdfName role)
Description copied from interface:IAccessibleElement
Sets the role of the accessiblee element. Set role tonull
if you don't want to tag this element. Note that all child elements won't also be tagged.- Specified by:
setRole
in interfaceIAccessibleElement
-
getId
public AccessibleElementId getId()
- Specified by:
getId
in interfaceIAccessibleElement
-
setId
public void setId(AccessibleElementId id)
- Specified by:
setId
in interfaceIAccessibleElement
-
isInline
public boolean isInline()
- Specified by:
isInline
in interfaceIAccessibleElement
-
getHeader
public PdfPTableHeader getHeader()
-
getBody
public PdfPTableBody getBody()
-
getFooter
public PdfPTableFooter getFooter()
-
getCellStartRowIndex
public int getCellStartRowIndex(int rowIdx, int colIdx)
Gets row index where cell overlapping (rowIdx, colIdx) starts- Parameters:
rowIdx
-colIdx
-- Returns:
- row index
- Since:
- iText 5.4.3
-
getFittingRows
public PdfPTable.FittingRows getFittingRows(float availableHeight, int startIdx)
Determine which rows fit on the page, respecting isSplitLate(). Note: sets max heights of the inspected rows as a side effect, just like PdfPTable.getRowHeight(int, boolean) does. Respect row.getMaxHeights() if it has been previously set (which might be independent of the height of individual cells). The last row written on the page will be chosen by the caller who might choose not the calculated one but an earlier one (due to mayNotBreak settings on the rows). The height of the chosen last row has to be corrected if splitLate == true by calling FittingRows.correctLastRowChosen() by the caller to avoid splitting the content of cells with open rowspans.- Since:
- iText 5.4.3
-
-