public class PdfPTable extends Object implements LargeElement
Table
.
In the last case when crossing pages the table always break at full rows; if a
row is bigger than the page it is dropped silently to avoid infinite loops.
A PdfPTableEvent can be associated to the table to do custom drawing when the table is rendered.
Modifier and Type | Field and Description |
---|---|
protected float[] |
absoluteWidths |
static int |
BACKGROUNDCANVAS
The index of the duplicate
PdfContentByte where the background will be drawn. |
static int |
BASECANVAS
The index of the original
PdfcontentByte . |
protected boolean |
complete
Indicates if the PdfPTable is complete once added to the document.
|
protected PdfPCell[] |
currentRow |
protected int |
currentRowIdx |
protected PdfPCell |
defaultCell |
protected int |
headerRows
Holds value of property headerRows.
|
protected boolean |
isColspan |
static int |
LINECANVAS
The index of the duplicate
PdfContentByte where the border lines will be drawn. |
protected float[] |
relativeWidths |
protected boolean |
rowCompleted
Keeps track of the completeness of the current row.
|
protected ArrayList |
rows |
protected int |
runDirection |
protected float |
spacingAfter
The spacing after the table.
|
protected float |
spacingBefore
The spacing before the table.
|
protected PdfPTableEvent |
tableEvent |
static int |
TEXTCANVAS
The index of the duplicate
PdfContentByte where the text will be drawn. |
protected float |
totalHeight |
protected float |
totalWidth |
protected float |
widthPercentage
Holds value of property widthPercentage.
|
ALIGN_BASELINE, ALIGN_BOTTOM, ALIGN_CENTER, ALIGN_JUSTIFIED, ALIGN_JUSTIFIED_ALL, ALIGN_LEFT, ALIGN_MIDDLE, ALIGN_RIGHT, ALIGN_TOP, ALIGN_UNDEFINED, ANCHOR, ANNOTATION, AUTHOR, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CELL, CHAPTER, CHUNK, CREATIONDATE, CREATOR, FOOTNOTE, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LIST, LISTITEM, MARKED, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE, YMARK
Modifier | Constructor and Description |
---|---|
protected |
PdfPTable() |
|
PdfPTable(float[] relativeWidths)
Constructs a
PdfPTable with the relative column widths. |
|
PdfPTable(int numColumns)
Constructs a
PdfPTable with numColumns columns. |
|
PdfPTable(PdfPTable table)
Constructs a copy of a
PdfPTable . |
Modifier and Type | Method and Description |
---|---|
void |
addCell(Image image)
Adds an Image as Cell.
|
void |
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(String text)
Adds a cell element.
|
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(boolean firsttime)
Calculates the heights of the table.
|
void |
calculateHeightsFast()
Calculates the heights of the table.
|
protected void |
calculateWidths() |
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 headers
|
boolean |
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.
|
ArrayList |
getChunks()
Gets all the chunks in this element.
|
PdfPCell |
getDefaultCell()
Gets the default
PdfPCell that will be used as
reference for all the addCell methods except
addCell(PdfPCell) . |
float |
getFooterHeight()
Gets the height of the rows that constitute the footer as defined by
setFooterRows() . |
int |
getFooterRows()
Gets the number of rows in the footer.
|
float |
getHeaderHeight()
Gets the height of the rows that constitute the header as defined by
setHeaderRows() . |
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.
|
boolean |
getKeepTogether()
Getter for property keepTogether
|
int |
getNumberOfColumns()
Returns the number of columns.
|
PdfPRow |
getRow(int idx)
Gets a row with a given index
(added by Jin-Hsia Yang).
|
float |
getRowHeight(int idx)
Gets the height of a particular row.
|
float |
getRowHeight(int idx,
boolean firsttime)
Gets the height of a particular row.
|
ArrayList |
getRows()
Gets an arraylist with all the rows in the table.
|
ArrayList |
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.
|
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 |
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 |
isLockedWidth()
Getter for property lockedWidth.
|
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.
|
boolean |
process(ElementListener listener)
Processes the element by adding it (or the different parts) to an
ElementListener . |
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 |
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 in
setTotalWidth() in Document.add() . |
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 |
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.
|
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.
|
public static final int BASECANVAS
PdfcontentByte
.public static final int BACKGROUNDCANVAS
PdfContentByte
where the background will be drawn.public static final int LINECANVAS
PdfContentByte
where the border lines will be drawn.public static final int TEXTCANVAS
PdfContentByte
where the text will be drawn.protected ArrayList rows
protected float totalHeight
protected PdfPCell[] currentRow
protected int currentRowIdx
protected PdfPCell defaultCell
protected float totalWidth
protected float[] relativeWidths
protected float[] absoluteWidths
protected PdfPTableEvent tableEvent
protected int headerRows
protected float widthPercentage
protected boolean isColspan
protected int runDirection
protected float spacingBefore
protected float spacingAfter
protected boolean complete
protected boolean rowCompleted
protected PdfPTable()
public PdfPTable(float[] relativeWidths)
PdfPTable
with the relative column widths.relativeWidths
- the relative column widthspublic PdfPTable(int numColumns)
PdfPTable
with numColumns
columns.numColumns
- the number of columnspublic PdfPTable(PdfPTable table)
PdfPTable
.table
- the PdfPTable
to be copiedpublic static PdfPTable shallowCopy(PdfPTable table)
table
- protected void copyFormat(PdfPTable sourceTable)
sourceTable
- public void setWidths(float[] relativeWidths) throws DocumentException
relativeWidths
- the relative widths of the table.DocumentException
- if the number of widths is different than the number
of columnspublic void setWidths(int[] relativeWidths) throws DocumentException
relativeWidths
- the relative widths of the table.DocumentException
- if the number of widths is different than the number
of columnsprotected void calculateWidths()
public void setTotalWidth(float totalWidth)
totalWidth
- the full width of the table.public void setTotalWidth(float[] columnWidth) throws DocumentException
columnWidth
- the absolute width of each columnDocumentException
- if the number of widths is different than the number
of columnspublic void setWidthPercentage(float[] columnWidth, Rectangle pageSize) throws DocumentException
columnWidth
- the absolute width of each columnpageSize
- the page sizeDocumentException
public float getTotalWidth()
public float calculateHeights(boolean firsttime)
firsttime
- if true, the heights of the rows will be recalculated.
This takes time; normally the heights of the rows are already calcultated,
so in most cases, it's save to use false as parameter.public void calculateHeightsFast()
public PdfPCell getDefaultCell()
PdfPCell
that will be used as
reference for all the addCell
methods except
addCell(PdfPCell)
.PdfPCell
public void addCell(PdfPCell cell)
cell
- the cell elementpublic void addCell(String text)
text
- the text for the cellpublic void addCell(PdfPTable table)
table
- the table to be added to the cellpublic void addCell(Image image)
image
- the Image
to add to the table.
This image will fit in the cellpublic void addCell(Phrase phrase)
phrase
- the Phrase
to be added to the cellpublic float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
canvases
is obtained from beginWritingRows()
.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 4 PdfContentByte
obtained from
beginWrittingRows()
beginWritingRows(com.lowagie.text.pdf.PdfContentByte)
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
canvases
is obtained from beginWritingRows()
.
The table event is only fired for complete rows.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 4 PdfContentByte
obtained from
beginWritingRows()
beginWritingRows(com.lowagie.text.pdf.PdfContentByte)
public float writeSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
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
- the PdfContentByte
where the rows will
be written topublic float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
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
- the PdfContentByte
where the rows will
be written topublic static PdfContentByte[] beginWritingRows(PdfContentByte canvas)
PdfContentByte
returned with the following order:
PdfPtable.BASECANVAS
- the original PdfContentByte
. 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.
canvas
- the PdfContentByte
where the rows will
be written toPdfContentByte
writeSelectedRows(int, int, float, float, PdfContentByte[])
public static void endWritingRows(PdfContentByte[] canvases)
canvases
- the array returned by beginWritingRows()
public int size()
public float getTotalHeight()
public float getRowHeight(int idx)
idx
- the row index (starts at 0)public float getRowHeight(int idx, boolean firsttime)
idx
- the row index (starts at 0)firsttime
- is this the first time the row heigh is calculated?public float getRowspanHeight(int rowIndex, int cellIndex)
rowIndex
- the row indexcellIndex
- the cell indexpublic float getHeaderHeight()
setHeaderRows()
.public float getFooterHeight()
setFooterRows()
.public boolean deleteRow(int rowNumber)
rowNumber
- the row to be deletedtrue
if the row was deletedpublic boolean deleteLastRow()
true
if the last row was deletedpublic void deleteBodyRows()
public int getNumberOfColumns()
public int getHeaderRows()
public void setHeaderRows(int headerRows)
Document
and the table crosses pages.headerRows
- the number of the top rows that constitute the headerpublic ArrayList getChunks()
public int type()
public boolean isContent()
Element
isContent
in interface Element
Element.isContent()
public boolean isNestable()
Element
isNestable
in interface Element
Element.isNestable()
public boolean process(ElementListener listener)
ElementListener
.public float getWidthPercentage()
public void setWidthPercentage(float widthPercentage)
widthPercentage
- the width percentage that the table will occupy in the pagepublic int getHorizontalAlignment()
public void setHorizontalAlignment(int horizontalAlignment)
horizontalAlignment
- the horizontal alignment of the table
relative to the pagepublic PdfPRow getRow(int idx)
idx
- public ArrayList getRows()
public ArrayList getRows(int start, int end)
start
- the first row in the selectionend
- the first row that isn't part of the selectionprotected PdfPRow adjustCellsInRow(int start, int end)
start
- the index of the start row (the one to adjust)end
- the index of the end row on the pagepublic void setTableEvent(PdfPTableEvent event)
event
- the table event for this tablepublic PdfPTableEvent getTableEvent()
public float[] getAbsoluteWidths()
public boolean isSkipFirstHeader()
public boolean isSkipLastFooter()
public void setSkipFirstHeader(boolean skipFirstHeader)
skipFirstHeader
- New value of property skipFirstHeader.public void setSkipLastFooter(boolean skipLastFooter)
skipLastFooter
- New value of property skipLastFooter.public void setRunDirection(int runDirection)
runDirection
- One of the following values:
PdfWriter.RUN_DIRECTION_DEFAULT, PdfWriter.RUN_DIRECTION_NO_BIDI,
PdfWriter.RUN_DIRECTION_LTR or PdfWriter.RUN_DIRECTION_RTL.public int getRunDirection()
public boolean isLockedWidth()
public void setLockedWidth(boolean lockedWidth)
setTotalWidth()
in Document.add()
.lockedWidth
- true
to use the value in setTotalWidth()
in Document.add()
public boolean isSplitRows()
public void setSplitRows(boolean splitRows)
true
by default.splitRows
- true to split; false otherwisepublic void setSpacingBefore(float spacing)
spacing
- the new spacingpublic void setSpacingAfter(float spacing)
spacing
- the new spacingpublic float spacingBefore()
public float spacingAfter()
public boolean isExtendLastRow()
public void setExtendLastRow(boolean extendLastRows)
extendLastRows
- true to extend the last row; false otherwisepublic void setExtendLastRow(boolean extendLastRows, boolean extendFinalRow)
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 tablepublic boolean isExtendLastRow(boolean newPageFollows)
public boolean isHeadersInEvent()
public void setHeadersInEvent(boolean headersInEvent)
headersInEvent
- true to include the headers; false otherwisepublic boolean isSplitLate()
public void setSplitLate(boolean splitLate)
splitLate
- the property valuepublic void setKeepTogether(boolean keepTogether)
keepTogether
- whether to try to keep the table on one pagepublic boolean getKeepTogether()
public int getFooterRows()
public void setFooterRows(int footerRows)
table.setHeaderRows(3); table.setFooterRows(1);Row 0 and 1 will be the header rows and row 2 will be the footer row.
footerRows
- the number of rows to be used for the footerpublic void completeRow()
public void flushContent()
LargeElement
flushContent
in interface LargeElement
LargeElement.flushContent()
public boolean isComplete()
LargeElement
isComplete
in interface LargeElement
LargeElement.isComplete()
public void setComplete(boolean complete)
LargeElement
setComplete
in interface LargeElement
complete
- false if you'll be adding more data after
adding the object to the document.LargeElement.setComplete(boolean)
Copyright © 2018. All rights reserved.