Save This Page
Home » iText-2.1.7 » com.lowagie » text » pdf » [javadoc | source]
com.lowagie.text.pdf
public class: PdfPTable [javadoc | source]
java.lang.Object
   com.lowagie.text.pdf.PdfPTable

All Implemented Interfaces:
    LargeElement

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
public static final  int BASECANVAS    The index of the original PdfcontentByte
public static final  int BACKGROUNDCANVAS    The index of the duplicate PdfContentByte where the background will be drawn. 
public static final  int LINECANVAS    The index of the duplicate PdfContentByte where the border lines will be drawn. 
public static final  int TEXTCANVAS    The index of the duplicate 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    Holds value of property headerRows. 
protected  float widthPercentage    Holds value of property widthPercentage. 
protected  boolean isColspan     
protected  int runDirection     
protected  float spacingBefore    The spacing before the table. 
protected  float spacingAfter    The spacing after the table. 
protected  boolean complete    Indicates if the PdfPTable is complete once added to the document.
    since: iText - 2.0.8
 
protected  boolean rowCompleted    Keeps track of the completeness of the current row.
    since: 2.1.6 -
 
Constructor:
 protected PdfPTable() 
 public PdfPTable(float[] relativeWidths) 
 public PdfPTable(int numColumns) 
 public PdfPTable(PdfPTable table) 
    Constructs a copy of a PdfPTable.
    Parameters:
    table - the PdfPTable to be copied
Method from com.lowagie.text.pdf.PdfPTable Summary:
addCell,   addCell,   addCell,   addCell,   addCell,   adjustCellsInRow,   beginWritingRows,   calculateHeights,   calculateHeightsFast,   calculateWidths,   completeRow,   copyFormat,   deleteBodyRows,   deleteLastRow,   deleteRow,   endWritingRows,   flushContent,   getAbsoluteWidths,   getChunks,   getDefaultCell,   getEventWidths,   getFooterHeight,   getFooterRows,   getHeaderHeight,   getHeaderRows,   getHorizontalAlignment,   getKeepTogether,   getNumberOfColumns,   getRow,   getRowHeight,   getRowHeight,   getRows,   getRows,   getRowspanHeight,   getRunDirection,   getTableEvent,   getTotalHeight,   getTotalWidth,   getWidthPercentage,   isComplete,   isContent,   isExtendLastRow,   isHeadersInEvent,   isLockedWidth,   isNestable,   isSkipFirstHeader,   isSkipLastFooter,   isSplitLate,   isSplitRows,   process,   rowSpanAbove,   setComplete,   setExtendLastRow,   setFooterRows,   setHeaderRows,   setHeadersInEvent,   setHorizontalAlignment,   setKeepTogether,   setLockedWidth,   setRunDirection,   setSkipFirstHeader,   setSkipLastFooter,   setSpacingAfter,   setSpacingBefore,   setSplitLate,   setSplitRows,   setTableEvent,   setTotalWidth,   setTotalWidth,   setWidthPercentage,   setWidthPercentage,   setWidths,   setWidths,   shallowCopy,   size,   spacingAfter,   spacingBefore,   type,   writeSelectedRows,   writeSelectedRows,   writeSelectedRows,   writeSelectedRows
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from com.lowagie.text.pdf.PdfPTable Detail:
 public  void addCell(PdfPCell cell) 
    Adds a cell element.
 public  void addCell(String text) 
    Adds a cell element.
 public  void addCell(PdfPTable table) 
    Adds a nested table.
 public  void addCell(Image image) 
    Adds an Image as Cell.
 public  void addCell(Phrase phrase) 
    Adds a cell element.
 protected PdfPRow adjustCellsInRow(int start,
    int end) 
    Calculates the extra height needed in a row because of rowspans.
 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 4 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.

 public float calculateHeights(boolean firsttime) 
    Calculates the heights of the table.
 public  void calculateHeightsFast() 
    Calculates the heights of the table.
 protected  void calculateWidths() 
 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.
 protected  void copyFormat(PdfPTable sourceTable) 
    Copies the format of the sourceTable without copying the content.
 public  void deleteBodyRows() 
    Removes all of the rows except headers
 public boolean deleteLastRow() 
    Deletes the last row in the table.
 public boolean deleteRow(int rowNumber) 
    Deletes a row from the table.
 public static  void endWritingRows(PdfContentByte[] canvases) 
    Finishes writing the table.
 public  void flushContent() 
 public float[] getAbsoluteWidths() 
    Gets the absolute sizes of each column width.
 public ArrayList getChunks() 
    Gets all the chunks in this element.
 public PdfPCell getDefaultCell() 
    Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell).
 float[][] getEventWidths(float xPos,
    int firstRow,
    int lastRow,
    boolean includeHeaders) 
 public float getFooterHeight() 
    Gets the height of the rows that constitute the footer as defined by setFooterRows().
 public int getFooterRows() 
    Gets the number of rows in the footer.
 public float getHeaderHeight() 
    Gets the height of the rows that constitute the header as defined by setHeaderRows().
 public int getHeaderRows() 
    Gets the number of the rows that constitute the header.
 public int getHorizontalAlignment() 
    Gets the horizontal alignment of the table relative to the page.
 public boolean getKeepTogether() 
    Getter for property keepTogether
 public int getNumberOfColumns() 
    Returns the number of columns.
 public PdfPRow getRow(int idx) 
    Gets a row with a given index (added by Jin-Hsia Yang).
 public float getRowHeight(int idx) 
    Gets the height of a particular row.
 public float getRowHeight(int idx,
    boolean firsttime) 
    Gets the height of a particular row.
 public ArrayList getRows() 
    Gets an arraylist with all the rows in the table.
 public ArrayList getRows(int start,
    int end) 
    Gets an arraylist with a selection of rows.
 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).
 public int getRunDirection() 
    Returns the run direction of the contents in the table.
 public PdfPTableEvent getTableEvent() 
    Gets the table event for this page.
 public float getTotalHeight() 
    Gets the total height of the table.
 public float getTotalWidth() 
    Gets the full width of the table.
 public float getWidthPercentage() 
    Gets the width percentage that the table will occupy in the page.
 public boolean isComplete() 
 public boolean isContent() 
 public boolean isExtendLastRow() 
    Gets the value of the last row extension.
 public boolean isHeadersInEvent() 
    Gets the header status inclusion in PdfPTableEvent.
 public boolean isLockedWidth() 
    Getter for property lockedWidth.
 public boolean isNestable() 
 public boolean isSkipFirstHeader() 
    Tells you if the first header needs to be skipped (for instance if the header says "continued from the previous page").
 public boolean isSkipLastFooter() 
    Tells you if the last footer needs to be skipped (for instance if the footer says "continued on the next page")
 public boolean isSplitLate() 
    Gets the property splitLate.
 public boolean isSplitRows() 
    Gets the split value.
 public boolean process(ElementListener listener) 
    Processes the element by adding it (or the different parts) to an ElementListener.
 boolean rowSpanAbove(int currRow,
    int currCol) 
    Checks if there are rows above belonging to a rowspan.
 public  void setComplete(boolean complete) 
 public  void setExtendLastRow(boolean extendLastRow) 
    When set the last row will be extended to fill all the remaining space to the bottom boundary.
 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.
 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 to Document and the table crosses pages.
 public  void setHeadersInEvent(boolean headersInEvent) 
    When set the PdfPTableEvent will include the headers.
 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%.
 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.
 public  void setLockedWidth(boolean lockedWidth) 
    Uses the value in setTotalWidth() in Document.add().
 public  void setRunDirection(int runDirection) 
    Sets the run direction of the contents of the table.
 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.
 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.
 public  void setSpacingAfter(float spacing) 
    Sets the spacing after this table.
 public  void setSpacingBefore(float spacing) 
    Sets the spacing before this table.
 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).
 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.
 public  void setTableEvent(PdfPTableEvent event) 
    Sets the table event for this table.
 public  void setTotalWidth(float totalWidth) 
    Sets the full width of the table.
 public  void setTotalWidth(float[] columnWidth) throws DocumentException 
    Sets the full width of the table from the absolute column width.
 public  void setWidthPercentage(float widthPercentage) 
    Sets the width percentage that the table will occupy in the page.
 public  void setWidthPercentage(float[] columnWidth,
    Rectangle pageSize) throws DocumentException 
    Sets the percentage width of the table from the absolute column width.
 public  void setWidths(float[] relativeWidths) throws DocumentException 
    Sets the relative widths of the table.
 public  void setWidths(int[] relativeWidths) throws DocumentException 
    Sets the relative widths of the table.
 public static PdfPTable shallowCopy(PdfPTable table) 
    Makes a shallow copy of a table (format without content).
 public int size() 
    Gets the number of rows in this table.
 public float spacingAfter() 
    Gets the spacing after this table.
 public float spacingBefore() 
    Gets the spacing before this table.
 public int type() 
    Gets the type of the text element.
 public float writeSelectedRows(int rowStart,
    int rowEnd,
    float xPos,
    float yPos,
    PdfContentByte[] canvases) 
    Writes the selected rows to the document. canvases is obtained from beginWritingRows().
 public float writeSelectedRows(int rowStart,
    int rowEnd,
    float xPos,
    float yPos,
    PdfContentByte canvas) 
    Writes the selected rows to the document.
 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 from beginWritingRows(). The table event is only fired for complete rows.
 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.