Class PdfPTable
- Namespace
- iTextSharp.text.pdf
- Assembly
- iTextSharp.LGPLv2.Core.dll
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. @author Paulo Soares (psoares@consiste.pt)
public class PdfPTable : ILargeElement, IElement
- Inheritance
-
PdfPTable
- Implements
- Inherited Members
Constructors
PdfPTable()
protected PdfPTable()
PdfPTable(int)
Constructs a PdfPTable with numColumns columns.
public PdfPTable(int numColumns)
Parameters
numColumns
intthe number of columns
PdfPTable(float[])
Constructs a PdfPTable with the relative column widths.
public PdfPTable(float[] relativeWidths)
Parameters
relativeWidths
float[]the relative column widths
PdfPTable(PdfPTable)
Constructs a copy of a PdfPTable .
public PdfPTable(PdfPTable table)
Parameters
table
PdfPTablethe PdfPTable to be copied
Fields
BACKGROUNDCANVAS
The index of the duplicate PdfContentByte where the background will be drawn.
public const int BACKGROUNDCANVAS = 1
Field Value
BASECANVAS
The index of the original PdfcontentByte .
public const int BASECANVAS = 0
Field Value
Complete
Indicates if the PdfPTable is complete once added to the document. @since iText 2.0.8
protected bool Complete
Field Value
CurrentRow
protected PdfPCell[] CurrentRow
Field Value
- PdfPCell[]
CurrentRowIdx
protected int CurrentRowIdx
Field Value
IsColspan
protected bool IsColspan
Field Value
LINECANVAS
The index of the duplicate PdfContentByte where the border lines will be drawn.
public const int LINECANVAS = 2
Field Value
RowCompleted
Keeps track of the completeness of the current row. @since 2.1.6
protected bool RowCompleted
Field Value
TEXTCANVAS
The index of the duplicate PdfContentByte where the text will be drawn.
public const int TEXTCANVAS = 3
Field Value
absoluteWidths
protected float[] absoluteWidths
Field Value
- float[]
defaultCell
protected PdfPCell defaultCell
Field Value
headerRows
Holds value of property headerRows.
protected int headerRows
Field Value
rows
protected List<PdfPRow> rows
Field Value
runDirection
protected int runDirection
Field Value
spacingAfter
The spacing after the table.
protected float spacingAfter
Field Value
spacingBefore
The spacing before the table.
protected float spacingBefore
Field Value
tableEvent
protected IPdfPTableEvent tableEvent
Field Value
totalHeight
protected float totalHeight
Field Value
totalWidth
protected float totalWidth
Field Value
widthPercentage
Holds value of property widthPercentage.
protected float widthPercentage
Field Value
Properties
AbsoluteWidths
Gets the absolute sizes of each column width.
public float[] AbsoluteWidths { get; }
Property Value
- float[]
he absolute sizes of each column width
Chunks
Gets all the chunks in this element.
public IList<Chunk> Chunks { get; }
Property Value
DefaultCell
Gets the default PdfPCell that will be used as reference for all the addCell methods except addCell(PdfPCell) .
public PdfPCell DefaultCell { get; }
Property Value
- PdfPCell
default PdfPCell
ElementComplete
@since iText 2.0.8 @see com.lowagie.text.LargeElement#isComplete()
public bool ElementComplete { get; set; }
Property Value
ExtendLastRow
Holds value of property extendLastRow.
public bool ExtendLastRow { get; set; }
Property Value
FooterHeight
Gets the height of the rows that constitute the header as defined by setFooterRows() . @since 2.1.1
public float FooterHeight { get; }
Property Value
- float
the height of the rows that constitute the footer
FooterRows
public int FooterRows { get; set; }
Property Value
HeaderHeight
Gets the height of the rows that constitute the header as defined by setHeaderRows() .
public float HeaderHeight { get; }
Property Value
- float
the height of the rows that constitute the header and footer
HeaderRows
public int HeaderRows { get; set; }
Property Value
HeadersInEvent
Holds value of property headersInEvent.
public bool HeadersInEvent { get; set; }
Property Value
HorizontalAlignment
Holds value of property horizontalAlignment.
public int HorizontalAlignment { get; set; }
Property Value
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 bool KeepTogether { get; set; }
Property Value
LockedWidth
Holds value of property lockedWidth.
public bool LockedWidth { get; set; }
Property Value
NumberOfColumns
Returns the number of columns. @since 2.1.1
public int NumberOfColumns { get; }
Property Value
- int
the number of columns.
RelativeWidths
public float[] RelativeWidths { get; }
Property Value
- float[]
Rows
Gets an arraylist with all the rows in the table.
public List<PdfPRow> Rows { get; }
Property Value
RunDirection
public int RunDirection { get; set; }
Property Value
Size
Gets the number of rows in this table.
public int Size { get; }
Property Value
- int
the number of rows in this table
SkipFirstHeader
Holds value of property skipFirstHeader.
public bool SkipFirstHeader { get; set; }
Property Value
SkipLastFooter
Tells you if the last footer needs to be skipped (for instance if the footer says "continued on the next page") @since 2.1.6
public bool SkipLastFooter { get; set; }
Property Value
- bool
Value of property skipLastFooter.
SpacingAfter
public float SpacingAfter { get; set; }
Property Value
SpacingBefore
public float SpacingBefore { get; set; }
Property Value
SplitLate
Holds value of property splitLate.
public bool SplitLate { get; set; }
Property Value
SplitRows
Holds value of property splitRows.
public bool SplitRows { get; set; }
Property Value
TableEvent
public IPdfPTableEvent TableEvent { get; set; }
Property Value
TotalHeight
Gets the total height of the table.
public float TotalHeight { get; }
Property Value
- float
the total height of the table
TotalWidth
Gets the full width of the table.
public float TotalWidth { get; set; }
Property Value
- float
the full width of the table
Type
Gets the type of the text element.
public int Type { get; }
Property Value
- int
a type
WidthPercentage
public float WidthPercentage { get; set; }
Property Value
Methods
AddCell(string)
Adds a cell element.
public void AddCell(string text)
Parameters
text
stringthe text for the cell
AddCell(Image)
Adds an Image as Cell.
public void AddCell(Image image)
Parameters
image
Imagethe Image to add to the table. This image will fit in the cell
AddCell(Phrase)
Adds a cell element.
public void AddCell(Phrase phrase)
Parameters
phrase
Phrasethe Phrase to be added to the cell
AddCell(PdfPCell)
Adds a cell element.
public void AddCell(PdfPCell cell)
Parameters
cell
PdfPCellthe cell element
AddCell(PdfPTable)
Adds a nested table.
public void AddCell(PdfPTable table)
Parameters
table
PdfPTablethe table to be added to the cell
AdjustCellsInRow(int, int)
Calculates the extra height needed in a row because of rowspans. @since 2.1.6
protected PdfPRow AdjustCellsInRow(int start, int end)
Parameters
start
intthe index of the start row (the one to adjust)
end
intthe index of the end row on the page
Returns
BeginWritingRows(PdfContentByte)
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. be written to @see #writeSelectedRows(int, int, float, float, PdfContentByte[])
public static PdfContentByte[] BeginWritingRows(PdfContentByte canvas)
Parameters
canvas
PdfContentBytethe PdfContentByte where the rows will
Returns
- PdfContentByte[]
an array of 4 PdfContentByte
CalculateHeights(bool)
Calculates the heights of the table. This takes time; normally the heights of the rows are already calcultated, so in most cases, it's save to use false as parameter. specify the width of the table with SetTotalWidth(). @since 2.1.5 added a parameter and a return type to an existing method, and made it public
public float CalculateHeights(bool firsttime)
Parameters
firsttime
boolif true, the heights of the rows will be recalculated.
Returns
- float
the total height of the table. Note that it will be 0 if you didn't
CalculateHeightsFast()
Calculates the heights of the table.
public void CalculateHeightsFast()
CalculateWidths()
protected void CalculateWidths()
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.
public void CompleteRow()
CopyFormat(PdfPTable)
Copies the format of the sourceTable without copying the content.
protected void CopyFormat(PdfPTable sourceTable)
Parameters
sourceTable
PdfPTable
DeleteBodyRows()
Removes all of the rows except headers
public void DeleteBodyRows()
DeleteLastRow()
Deletes the last row in the table.
public bool DeleteLastRow()
Returns
- bool
true if the last row was deleted
DeleteRow(int)
Deletes a row from the table.
public bool DeleteRow(int rowNumber)
Parameters
rowNumber
intthe row to be deleted
Returns
- bool
true if the row was deleted
EndWritingRows(PdfContentByte[])
Finishes writing the table.
public static void EndWritingRows(PdfContentByte[] canvases)
Parameters
canvases
PdfContentByte[]the array returned by beginWritingRows()
FlushContent()
@since iText 2.0.8 @see com.lowagie.text.LargeElement#flushContent()
public void FlushContent()
GetRow(int)
Gets a row with a given index (added by Jin-Hsia Yang).
public PdfPRow GetRow(int idx)
Parameters
idx
int
Returns
- PdfPRow
the row at position idx
GetRowHeight(int)
Gets the height of a particular row.
public float GetRowHeight(int idx)
Parameters
idx
intthe row index (starts at 0)
Returns
- float
the height of a particular row
GetRowHeight(int, bool)
Gets the height of a particular row. @since 3.0.0
public float GetRowHeight(int idx, bool firsttime)
Parameters
idx
intthe row index (starts at 0)
firsttime
boolis this the first time the row heigh is calculated?
Returns
- float
the height of a particular row
GetRows(int, int)
Gets an arraylist with a selection of rows. @since 2.1.6
public IList<PdfPRow> GetRows(int start, int end)
Parameters
Returns
GetRowspanHeight(int, int)
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). @since 2.1.6
public float GetRowspanHeight(int rowIndex, int cellIndex)
Parameters
Returns
- float
the height of a particular row including rowspan
IsContent()
@see com.lowagie.text.Element#isContent() @since iText 2.0.8
public bool IsContent()
Returns
IsNestable()
@see com.lowagie.text.Element#isNestable() @since iText 2.0.8
public bool IsNestable()
Returns
Process(IElementListener)
Processes the element by adding it (or the different parts) to an ElementListener .
public bool Process(IElementListener listener)
Parameters
listener
IElementListeneran ElementListener
Returns
- bool
true if the element was processed successfully
SetTotalWidth(float[])
Sets the full width of the table from the absolute column width. @throws DocumentException if the number of widths is different than the number of columns
public void SetTotalWidth(float[] columnWidth)
Parameters
columnWidth
float[]the absolute width of each column
SetWidthPercentage(float[], Rectangle)
Sets the percentage width of the table from the absolute column width. @throws DocumentException
public void SetWidthPercentage(float[] columnWidth, Rectangle pageSize)
Parameters
SetWidths(int[])
Sets the relative widths of the table. @throws DocumentException if the number of widths is different than the number of columns
public void SetWidths(int[] relativeWidths)
Parameters
relativeWidths
int[]the relative widths of the table.
SetWidths(float[])
Sets the relative widths of the table. @throws DocumentException if the number of widths is different than the number of columns
public void SetWidths(float[] relativeWidths)
Parameters
relativeWidths
float[]the relative widths of the table.
ShallowCopy(PdfPTable)
Makes a shallow copy of a table (format without content).
public static PdfPTable ShallowCopy(PdfPTable table)
Parameters
table
PdfPTable
Returns
- PdfPTable
a shallow copy of the table
WriteSelectedRows(int, int, int, int, float, float, PdfContentByte)
Writes the selected rows 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. rows to the end are written be written to
public float WriteSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
Parameters
colStart
intthe first column to be written, zero index
colEnd
intthe last column to be written + 1. If it is -1 all the
rowStart
intthe first row to be written, zero index
rowEnd
intthe last row to be written + 1. If it is -1 all the
xPos
floatthe x write coodinate
yPos
floatthe y write coodinate
canvas
PdfContentBytethe PdfContentByte where the rows will
Returns
- float
the y coordinate position of the bottom of the last row
WriteSelectedRows(int, int, int, int, float, float, PdfContentByte[])
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. columns to the end are written rows to the end are written beginWrittingRows() @see #beginWritingRows(com.lowagie.text.pdf.PdfContentByte)
public float WriteSelectedRows(int colStart, int colEnd, int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
Parameters
colStart
intthe first column to be written, zero index
colEnd
intthe last column to be written + 1. If it is -1 all the
rowStart
intthe first row to be written, zero index
rowEnd
intthe last row to be written + 1. If it is -1 all the
xPos
floatthe x write coodinate
yPos
floatthe y write coodinate
canvases
PdfContentByte[]an array of 4 PdfContentByte obtained from
Returns
- float
the y coordinate position of the bottom of the last row
WriteSelectedRows(int, int, float, float, PdfContentByte)
Writes the selected rows to the document. rows to the end are written be written to
public float WriteSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte canvas)
Parameters
rowStart
intthe first row to be written, zero index
rowEnd
intthe last row to be written + 1. If it is -1 all the
xPos
floatthe x write coodinate
yPos
floatthe y write coodinate
canvas
PdfContentBytethe PdfContentByte where the rows will
Returns
- float
the y coordinate position of the bottom of the last row
WriteSelectedRows(int, int, float, float, PdfContentByte[])
Writes the selected rows to the document. canvases is obtained from beginWritingRows() . rows to the end are written beginWrittingRows() @see #beginWritingRows(com.lowagie.text.pdf.PdfContentByte)
public float WriteSelectedRows(int rowStart, int rowEnd, float xPos, float yPos, PdfContentByte[] canvases)
Parameters
rowStart
intthe first row to be written, zero index
rowEnd
intthe last row to be written + 1. If it is -1 all the
xPos
floatthe x write coodinate
yPos
floatthe y write coodinate
canvases
PdfContentByte[]an array of 4 PdfContentByte obtained from
Returns
- float
the y coordinate position of the bottom of the last row