|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.lowagie.text.pdf.PdfPTable
This is a table that can be put at an absolute position but can also
be added to the document as the class 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.
Field Summary | |
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 PdfPCell[] |
currentRow
|
protected int |
currentRowIdx
|
protected PdfPCell |
defaultCell
|
private boolean |
extendLastRow
Holds value of property extendLastRow. |
private int |
footerRows
Holds value of property footerRows. |
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 boolean |
isColspan
|
private boolean |
keepTogether
Defines if the table should be kept on one page if possible |
static int |
LINECANVAS
The index of the duplicate PdfContentByte where the border lines will be drawn. |
private boolean |
lockedWidth
Holds value of property lockedWidth. |
protected float[] |
relativeWidths
|
protected ArrayList |
rows
|
protected int |
runDirection
|
private boolean |
skipFirstHeader
Holds value of property skipFirstHeader. |
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 duplicate PdfContentByte 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.lowagie.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, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CELL, CHAPTER, CHUNK, CREATIONDATE, CREATOR, GRAPHIC, HEADER, IMGRAW, IMGTEMPLATE, JPEG, KEYWORDS, LIST, LISTITEM, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, ROW, SECTION, SUBJECT, TABLE, TITLE |
Constructor Summary | |
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 . |
Method Summary | |
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. |
static PdfContentByte[] |
beginWritingRows(PdfContentByte canvas)
Gets and initializes the 4 layers where the table is written to. |
(package private) void |
calculateHeights()
|
void |
calculateHeightsFast()
Calculates the heights of the table. |
private void |
calculateWidths()
|
private 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. |
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) . |
(package private) float[][] |
getEventWidths(float xPos,
int firstRow,
int lastRow,
boolean includeHeaders)
|
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()
|
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. |
ArrayList |
getRows()
Gets an arraylist with all the rows in the table. |
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 |
isExtendLastRow()
Gets the value of the last row extension. |
boolean |
isHeadersInEvent()
Gets the header status inclusion in PdfPTableEvent. |
boolean |
isLockedWidth()
Getter for property lockedWidth. |
boolean |
isSkipFirstHeader()
Getter for property skipFirstHeader. |
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 |
setExtendLastRow(boolean extendLastRow)
When set the last row will be extended to fill all the remaining space to the bottom boundary. |
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 p_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 |
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 before 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 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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.lowagie.text.Element |
toString |
Field Detail |
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
private int horizontalAlignment
private boolean skipFirstHeader
protected boolean isColspan
protected int runDirection
private boolean lockedWidth
private boolean splitRows
protected float spacingBefore
protected float spacingAfter
private boolean extendLastRow
private boolean headersInEvent
private boolean splitLate
private boolean keepTogether
private int footerRows
Constructor Detail |
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 copiedMethod Detail |
public static PdfPTable shallowCopy(PdfPTable table)
table
-
private 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 columnsprivate 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 column
DocumentException
- 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 size
DocumentException
public float getTotalWidth()
void calculateHeights()
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 coodinateyPos
- the y write coodinatecanvases
- 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 coodinateyPos
- the y write coodinatecanvases
- an array of 4 PdfContentByte
obtained from
beginWrittingRows()
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 coodinateyPos
- the y write coodinatecanvas
- the PdfContentByte
where the rows will
be written to
public float writeSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
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 therowStart
- 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 coodinateyPos
- the y write coodinatecanvas
- the PdfContentByte
where the rows will
be written to
public 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 to
PdfContentByte
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 getHeaderHeight()
setHeaderRows()
.
public boolean deleteRow(int rowNumber)
rowNumber
- the row to be deleted
true
if the row was deletedpublic boolean deleteLastRow()
true
if the last row was deletedpublic void deleteBodyRows()
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()
getChunks
in interface Element
ArrayList
public int type()
type
in interface Element
public boolean process(ElementListener listener)
ElementListener
.
process
in interface Element
listener
- an ElementListener
true
if the element was processed successfullypublic 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 void setTableEvent(PdfPTableEvent event)
event
- the table event for this tablepublic PdfPTableEvent getTableEvent()
public float[] getAbsoluteWidths()
float[][] getEventWidths(float xPos, int firstRow, int lastRow, boolean includeHeaders)
public boolean isSkipFirstHeader()
public void setSkipFirstHeader(boolean skipFirstHeader)
skipFirstHeader
- New value of property skipFirstHeader.public void setRunDirection(int runDirection)
runDirection
- 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 extendLastRow)
extendLastRow
- true to extend the last row; false otherwisepublic boolean isHeadersInEvent()
public void setHeadersInEvent(boolean headersInEvent)
headersInEvent
- true to include the headers; false otherwisepublic boolean isSplitLate()
public void setSplitLate(boolean splitLate)
It's only meaningful if setSplitRows(true).
splitLate
- the property valuepublic void setKeepTogether(boolean p_KeepTogether)
p_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 footer
|
![]() |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |