Table of Contents

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 int

the 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 PdfPTable

the 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

int

BASECANVAS

The index of the original PdfcontentByte .

public const int BASECANVAS = 0

Field Value

int

Complete

Indicates if the PdfPTable is complete once added to the document. @since iText 2.0.8

protected bool Complete

Field Value

bool

CurrentRow

protected PdfPCell[] CurrentRow

Field Value

PdfPCell[]

CurrentRowIdx

protected int CurrentRowIdx

Field Value

int

IsColspan

protected bool IsColspan

Field Value

bool

LINECANVAS

The index of the duplicate PdfContentByte where the border lines will be drawn.

public const int LINECANVAS = 2

Field Value

int

RowCompleted

Keeps track of the completeness of the current row. @since 2.1.6

protected bool RowCompleted

Field Value

bool

TEXTCANVAS

The index of the duplicate PdfContentByte where the text will be drawn.

public const int TEXTCANVAS = 3

Field Value

int

absoluteWidths

protected float[] absoluteWidths

Field Value

float[]

defaultCell

protected PdfPCell defaultCell

Field Value

PdfPCell

headerRows

Holds value of property headerRows.

protected int headerRows

Field Value

int

rows

protected List<PdfPRow> rows

Field Value

List<PdfPRow>

runDirection

protected int runDirection

Field Value

int

spacingAfter

The spacing after the table.

protected float spacingAfter

Field Value

float

spacingBefore

The spacing before the table.

protected float spacingBefore

Field Value

float

tableEvent

protected IPdfPTableEvent tableEvent

Field Value

IPdfPTableEvent

totalHeight

protected float totalHeight

Field Value

float

totalWidth

protected float totalWidth

Field Value

float

widthPercentage

Holds value of property widthPercentage.

protected float widthPercentage

Field Value

float

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

IList<Chunk>

an ArrayList

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

bool

ExtendLastRow

Holds value of property extendLastRow.

public bool ExtendLastRow { get; set; }

Property Value

bool

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

int

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

int

HeadersInEvent

Holds value of property headersInEvent.

public bool HeadersInEvent { get; set; }

Property Value

bool

HorizontalAlignment

Holds value of property horizontalAlignment.

public int HorizontalAlignment { get; set; }

Property Value

int

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

bool

LockedWidth

Holds value of property lockedWidth.

public bool LockedWidth { get; set; }

Property Value

bool

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

List<PdfPRow>

an arraylist

RunDirection

public int RunDirection { get; set; }

Property Value

int

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

bool

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

float

SpacingBefore

public float SpacingBefore { get; set; }

Property Value

float

SplitLate

Holds value of property splitLate.

public bool SplitLate { get; set; }

Property Value

bool

SplitRows

Holds value of property splitRows.

public bool SplitRows { get; set; }

Property Value

bool

TableEvent

public IPdfPTableEvent TableEvent { get; set; }

Property Value

IPdfPTableEvent

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

float

Methods

AddCell(string)

Adds a cell element.

public void AddCell(string text)

Parameters

text string

the text for the cell

AddCell(Image)

Adds an Image as Cell.

public void AddCell(Image image)

Parameters

image Image

the 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 Phrase

the Phrase to be added to the cell

AddCell(PdfPCell)

Adds a cell element.

public void AddCell(PdfPCell cell)

Parameters

cell PdfPCell

the cell element

AddCell(PdfPTable)

Adds a nested table.

public void AddCell(PdfPTable table)

Parameters

table PdfPTable

the 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 int

the index of the start row (the one to adjust)

end int

the index of the end row on the page

Returns

PdfPRow

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 PdfContentByte

the 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 bool

if 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 int

the 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 int

the 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 int

the row index (starts at 0)

firsttime bool

is 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

start int

the first row in the selection

end int

the first row that isn't part of the selection

Returns

IList<PdfPRow>

a selection of rows

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

rowIndex int

the row index

cellIndex int

the cell index

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

bool

IsNestable()

@see com.lowagie.text.Element#isNestable() @since iText 2.0.8

public bool IsNestable()

Returns

bool

Process(IElementListener)

Processes the element by adding it (or the different parts) to an ElementListener .

public bool Process(IElementListener listener)

Parameters

listener IElementListener

an 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

columnWidth float[]

the absolute width of each column

pageSize Rectangle

the page size

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 int

the first column to be written, zero index

colEnd int

the last column to be written + 1. If it is -1 all the

rowStart int

the first row to be written, zero index

rowEnd int

the last row to be written + 1. If it is -1 all the

xPos float

the x write coodinate

yPos float

the y write coodinate

canvas PdfContentByte

the 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 int

the first column to be written, zero index

colEnd int

the last column to be written + 1. If it is -1 all the

rowStart int

the first row to be written, zero index

rowEnd int

the last row to be written + 1. If it is -1 all the

xPos float

the x write coodinate

yPos float

the 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 int

the first row to be written, zero index

rowEnd int

the last row to be written + 1. If it is -1 all the

xPos float

the x write coodinate

yPos float

the y write coodinate

canvas PdfContentByte

the 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 int

the first row to be written, zero index

rowEnd int

the last row to be written + 1. If it is -1 all the

xPos float

the x write coodinate

yPos float

the 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