|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.itextpdf.text.pdf.PdfPTable
public class 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.
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 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
|
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 java.util.ArrayList<PdfPRow> |
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. |
| 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, CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFBLOCK, CCITT_ENDOFLINE, CCITTG3_1D, CCITTG3_2D, CCITTG4, CHAPTER, CHUNK, CREATIONDATE, CREATOR, HEADER, IMGRAW, IMGTEMPLATE, JBIG2, JPEG, JPEG2000, KEYWORDS, LIST, LISTITEM, MARKED, MULTI_COLUMN_TEXT, PARAGRAPH, PHRASE, PRODUCER, PTABLE, RECTANGLE, SECTION, SUBJECT, TITLE, WRITABLE_DIRECT, YMARK |
| 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(java.lang.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()
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. |
java.util.List<Chunk> |
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. |
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. |
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. |
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. |
void |
normalizeHeadersFooters()
Makes sure the footers value is lower than the headers value. |
boolean |
process(ElementListener listener)
Processes the element by adding it (or the different parts) to an ElementListener. |
void |
resetColumnCount(int newColCount)
Changes the number of columns. |
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. |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface com.itextpdf.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 java.util.ArrayList<PdfPRow> rows
protected float totalHeight
protected PdfPCell[] currentRow
protected int currentColIdx
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
| 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 copied| Method Detail |
|---|
public 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 columns
public 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 column
DocumentException - if the number of widths is different than the number
of columns
public void setWidthPercentage(float[] columnWidth,
Rectangle pageSize)
throws DocumentException
columnWidth - the absolute width of each columnpageSize - the page size
DocumentExceptionpublic float getTotalWidth()
public float calculateHeights()
public void resetColumnCount(int newColCount)
newColCount - the new number of columnspublic PdfPCell getDefaultCell()
PdfPCell that will be used as
reference for all the addCell methods except
addCell(PdfPCell).
PdfPCellpublic void addCell(PdfPCell cell)
cell - the cell elementpublic void addCell(java.lang.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 cell
public 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.itextpdf.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.itextpdf.text.pdf.PdfContentByte)
public float writeSelectedRows(int colStart,
int colEnd,
int rowStart,
int rowEnd,
float xPos,
float yPos,
PdfContentByte[] canvases,
boolean reusable)
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()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.
beginWritingRows(com.itextpdf.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 to
public 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 to
public float writeSelectedRows(int colStart,
int colEnd,
int rowStart,
int rowEnd,
float xPos,
float yPos,
PdfContentByte canvas,
boolean reusable)
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 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.
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
PdfContentBytewriteSelectedRows(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)
protected 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 index
public boolean hasRowspan(int rowIdx)
public void normalizeHeadersFooters()
public float getHeaderHeight()
setHeaderRows().
public float getFooterHeight()
setFooterRows().
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 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 java.util.List<Chunk> getChunks()
getChunks in interface ElementArrayListpublic int type()
type in interface Elementpublic boolean isContent()
Element
isContent in interface ElementElement.isContent()public boolean isNestable()
Element
isNestable in interface ElementElement.isNestable()public boolean process(ElementListener listener)
ElementListener.
process in interface Elementlistener - 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 java.util.ArrayList<PdfPRow> getRows()
public java.util.ArrayList<PdfPRow> getRows(int start,
int end)
start - the first row in the selectionend - the first row that isn't part of the selection
protected 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)
setSpacingBefore in interface Spaceablespacing - the new spacingpublic void setSpacingAfter(float spacing)
setSpacingAfter in interface Spaceablespacing - the new spacingpublic float spacingBefore()
public float spacingAfter()
public boolean isExtendLastRow()
public void setExtendLastRow(boolean extendLastRows)
extendLastRows - true to extend the last row; false otherwise
public 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 LargeElementLargeElement.flushContent()public boolean isComplete()
LargeElement
isComplete in interface LargeElementLargeElement.isComplete()public void setComplete(boolean complete)
LargeElement
setComplete in interface LargeElementcomplete - false if you'll be adding more data after
adding the object to the document.LargeElement.setComplete(boolean)public float getSpacingBefore()
Spaceable
getSpacingBefore in interface Spaceablepublic float getSpacingAfter()
Spaceable
getSpacingAfter in interface Spaceable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||