Table of Contents

Class Table

Namespace
PDFjet.NET
Assembly
PDFjet.dll

Used to create table objects and draw them on a page.

Please see Example_20.

public class Table : IDrawable
Inheritance
Table
Implements
Inherited Members

Constructors

Table()

Create a table object.

public Table()

Table(Font, Font, string)

Creates a table from a text file with comma, pipe or tab separated values. The first line is the header row and uses f1; the other lines use f2. Every row gets as many cells as the first line has fields. A quoted field is read as RFC 4180 reads it, and a line break inside one goes on to the next line of the file and is drawn as a space.

public Table(Font f1, Font f2, string fileName)

Parameters

f1 Font

the font for the header row.

f2 Font

the font for the other rows.

fileName string

the file name.

Methods

AutoAdjustColumnWidths()

Auto adjusts the widths of all columns so that they are just wide enough to hold the text without truncation.

public Table AutoAdjustColumnWidths()

Returns

Table

this Table object.

DrawOn(PDF, Page, List<Page>, PageSize)

Draws this table as DrawOn(pdf, pages, pageSize) does, starting on first: a page that has other content above the table, such as a heading, which SetFirstPageTopMargin puts the table under. The next pages are new, and are added to the list; first is not.

public float[] DrawOn(PDF pdf, Page first, List<Page> pages, PageSize pageSize)

Parameters

pdf PDF

the PDF document.

first Page

the page the table starts on.

pages List<Page>

the list that receives the new pages.

pageSize PageSize

the page size, for example Letter.PORTRAIT.

Returns

float[]

the x and y coordinates of the bottom right corner of the table on the last page.

DrawOn(PDF, List<Page>, PageSize)

Draws this table on as many new pages as it needs. The pages are created detached and added to the list; add them to the PDF afterwards.

public float[] DrawOn(PDF pdf, List<Page> pages, PageSize pageSize)

Parameters

pdf PDF

the PDF document.

pages List<Page>

the list that receives the new pages.

pageSize PageSize

the page size, for example Letter.PORTRAIT.

Returns

float[]

the x and y coordinates of the bottom right corner of the table on the last page.

DrawOn(Page)

Draws this table on the specified page.

public float[] DrawOn(Page page)

Parameters

page Page

the page to draw this table on.

Returns

float[]

the x and y coordinates of the bottom right corner of the table.

FitToWidth(float)

Makes the table the width given, sharing it among the columns by the widths they have: after AutoAdjustColumnWidths, by the text each holds. Text wraps to the widths.

public Table FitToWidth(float width)

Parameters

width float

the width of the table.

Returns

Table

this Table object.

GetCellAt(int, int)

Returns the cell at the specified row and column.

public Cell GetCellAt(int row, int col)

Parameters

row int

the specified row.

col int

the specified column.

Returns

Cell

the cell at the specified row and column.

GetColumn(int)

Returns a list of cells for the specified column.

public List<Cell> GetColumn(int index)

Parameters

index int

the index of the specified column.

Returns

List<Cell>

the list of cells.

GetColumnWidth(int)

Returns the column width of the column at the specified index.

public float GetColumnWidth(int index)

Parameters

index int

the index of the column.

Returns

float

the width of the column.

GetRow(int)

Returns a list of cells for the specified row.

public List<Cell> GetRow(int index)

Parameters

index int

the index of the specified row.

Returns

List<Cell>

the list of cells.

GetRowsRendered()

Returns the number of rows below the header rows that are drawn so far, counting each line of wrapped cell text as a row, or -1 when all rows are drawn.

public int GetRowsRendered()

Returns

int

the number of rendered rows.

GetWidth()

Returns the width of this table when drawn on a page.

public float GetWidth()

Returns

float

the width of this table.

KeepRowWithNext(int)

Keeps the row with the specified index on the same page as the next row, as a heading row is kept with the rows under it: a page break does not fall between them, and moves both to the next page. Rows kept with the next one one after another are kept together, unless together they are taller than a page. Call it before the table is drawn.

public Table KeepRowWithNext(int index)

Parameters

index int

the index of the row.

Returns

Table

this Table object.

RemoveLineBetweenRows(int, int)

Removes the horizontal lines between the rows from index1 to index2.

public Table RemoveLineBetweenRows(int index1, int index2)

Parameters

index1 int
index2 int

Returns

Table

RightAlignNumbers()

Aligns to the right the cells whose text is a number, such as 1,234.50, (1,234.50), -5 or 1.5E+3. The periods, commas and apostrophes are ignored, and the number can be in parentheses.

public Table RightAlignNumbers()

Returns

Table

SetAlternateRowColor(int)

Colors every other row of the body of the table, the second, the fourth and so on, counting the rows of the data and not those of each page, as BigTable.SetShadingColor shades its rows. The lines a row wraps into have its color, and a cell with a background of its own keeps it; the header and the footer rows are not striped. Color.transparent turns the stripes off.

public Table SetAlternateRowColor(int color)

Parameters

color int

the color as a 0xRRGGBB value, for example Color.whitesmoke.

Returns

Table

this Table object.

SetAlternateRowColor(float[])

Colors every other row of the body of the table, as SetAlternateRowColor(int) does, with a color of red, green and blue values from 0 to 1. null turns the stripes off.

public Table SetAlternateRowColor(float[] color)

Parameters

color float[]

the red, green and blue values.

Returns

Table

this Table object.

SetBottomMargin(float)

Sets the bottom margin for this table.

public Table SetBottomMargin(float bottomMargin)

Parameters

bottomMargin float

the margin.

Returns

Table

this Table object.

SetBroughtForwardSum(int, int, int)

Makes the cell of a header row show the sum of its column over all the rows of the pages before: the total brought forward, which the cell that SetRunningSum marks shows at the end of the page before. A header row with such a cell is drawn from the second page on, under the header rows above it, and not on the first page, which has nothing to bring forward; in a PDF/UA document it is an artifact, as the header rows are on those pages. The numbers are read and the sum is written as SetPageSum reads and writes them.

public Table SetBroughtForwardSum(int row, int column, int decimals)

Parameters

row int

the index of a header row, see SetTableData.

column int

the index of the column.

decimals int

the number of decimals, from 0 to 9.

Returns

Table

this Table object.

SetCellBorderColor(int)

Sets the color of the cell border lines. Color.transparent leaves it unchanged.

public Table SetCellBorderColor(int color)

Parameters

color int

the color of the cell border lines.

Returns

Table

this Table object.

SetCellBorderColor(float[])

Sets the color of the cell border lines.

public Table SetCellBorderColor(float[] rgbColor)

Parameters

rgbColor float[]

the color as red, green and blue components from 0.0 to 1.0.

Returns

Table

this Table object.

SetCellBorderWidth(float)

Sets the width of the cell border lines.

public Table SetCellBorderWidth(float width)

Parameters

width float

the width of the cell border lines.

Returns

Table

this Table object.

SetCellBorders(bool)

Sets all table cells borders.

public Table SetCellBorders(bool borders)

Parameters

borders bool

true or false.

Returns

Table

this Table object.

SetCellPadding(float, float)

Sets the padding of every cell of the table, as SetCellBorders sets their borders: side at the left and the right of the text, vertical over and under it, in points. A table whose cells have borders reads better with more than the 2 points of a new cell on every side, such as 4 at the sides and 3 over and under. A cell set afterwards keeps its own padding, and the rows a wrapped cell adds under it have the side padding of the cell, none over them and a new cell's under them.

public Table SetCellPadding(float side, float vertical)

Parameters

side float

the padding at the left and the right of each cell.

vertical float

the padding over and under the text of each cell.

Returns

Table

this Table object.

SetColumnWidth(int, float)

Sets the width of the column with the specified index.

public Table SetColumnWidth(int index, float width)

Parameters

index int

the index of specified column.

width float

the specified width.

Returns

Table

this Table object.

SetColumnWidthsInPercent(params float[])

Gives the columns, from the first, their percentages of the width of the table that SetWidth sets, whichever of the two is called first. The columns that have none share what is left of 100 equally, and the widths are then made to add up to the width of the table, so percentages that do not add up to 100 are shares of it. Text wraps to the widths.

public Table SetColumnWidthsInPercent(params float[] percents)

Parameters

percents float[]

the percentages of the columns.

Returns

Table

this Table object.

SetFirstPageTopMargin(float)

Sets the top margin on the first page when the table spans several pages.

public Table SetFirstPageTopMargin(float firstPageTopMargin)

Parameters

firstPageTopMargin float

Returns

Table

SetFontInColumn(int, Font)

Sets the font and the font size of the cells in the specified column.

public Table SetFontInColumn(int index, Font font)

Parameters

index int

the column index.

font Font

the font.

Returns

Table

this Table object.

SetFontInRow(int, Font)

Sets the font and the font size of the cells in the specified row.

public Table SetFontInRow(int index, Font font)

Parameters

index int

the row index.

font Font

the font.

Returns

Table

this Table object.

SetFooterRowStyle(Font, int, int)

Sets the font, the text color and the background color of the footer rows, the rows SetNumberOfFooterRows names, as SetHeaderRowStyle sets those of the header rows. Call it after SetNumberOfFooterRows.

public Table SetFooterRowStyle(Font font, int textColor, int backgroundColor)

Parameters

font Font

the font, or null to keep the fonts of the cells.

textColor int

the text color, or Color.transparent to keep it.

backgroundColor int

the background color, or Color.transparent to keep it.

Returns

Table

this Table object.

SetHeaderRowStyle(Font, int, int)

Sets the font, the text color and the background color of the header rows, the rows SetTableData names, as SetFontInRow and SetTextColorInRow set them for one row. Call it after SetTableData and before AutoAdjustColumnWidths, which measures the text in the font.

public Table SetHeaderRowStyle(Font font, int textColor, int backgroundColor)

Parameters

font Font

the font, or null to keep the fonts of the cells.

textColor int

the text color, or Color.transparent to keep it.

backgroundColor int

the background color, or Color.transparent to keep it.

Returns

Table

this Table object.

SetLocation(float, float)

Sets the location (x, y) of the top left corner of this table on the page.

public Table SetLocation(float x, float y)

Parameters

x float

the x coordinate of the top left point of the table.

y float

the y coordinate of the top left point of the table.

Returns

Table

SetNumberOfFooterRows(int)

Makes the last rows of the table data footer rows, which are drawn again at the end of the table on every page, under the last row the page holds, as the header rows are drawn again at the top. A page leaves room for them. In a PDF/UA document they are rows of the table once, where the table ends, and artifacts on the other pages.

public Table SetNumberOfFooterRows(int numOfFooterRows)

Parameters

numOfFooterRows int

the number of footer rows at the end of the data.

Returns

Table

this Table object.

SetPageSum(int, int, int)

Makes the cell of a footer row show the sum of its column over the rows of each page: the page total. The numbers are read as RightAlignNumbers reads them, with commas and apostrophes between the thousands and a period before the decimals, and a cell that has no number is left out. The sum has the number of decimals, rounded half away from zero, and commas between the thousands. Until the table is drawn the cell has the sum of all the rows, so that AutoAdjustColumnWidths leaves room for it; its text is not wrapped.

public Table SetPageSum(int row, int column, int decimals)

Parameters

row int

the index of a footer row, see SetNumberOfFooterRows.

column int

the index of the column.

decimals int

the number of decimals, from 0 to 9.

Returns

Table

this Table object.

SetRunningSum(int, int, int)

Makes the cell of a footer row show the sum of its column over all the rows up to the end of each page: the total carried forward, which is the total of the table on its last page. The numbers are read and the sum is written as SetPageSum reads and writes them.

public Table SetRunningSum(int row, int column, int decimals)

Parameters

row int

the index of a footer row, see SetNumberOfFooterRows.

column int

the index of the column.

decimals int

the number of decimals, from 0 to 9.

Returns

Table

this Table object.

SetTableData(List<List<Cell>>)

Sets the table data.

public Table SetTableData(List<List<Cell>> tableData)

Parameters

tableData List<List<Cell>>

the table data.

Returns

Table

this Table object.

SetTableData(List<List<Cell>>, int)

Sets the table data and specifies the number of header rows in this data. The header rows are drawn again at the top of every page.

public Table SetTableData(List<List<Cell>> tableData, int numOfHeaderRows)

Parameters

tableData List<List<Cell>>

the table data.

numOfHeaderRows int

the number of header rows in this data.

Returns

Table

this Table object.

SetTextAlignmentInColumn(int, Alignment)

Sets the text alignment in the specified column.

public Table SetTextAlignmentInColumn(int index, Alignment alignment)

Parameters

index int

the index of the specified column.

alignment Alignment

the specified alignment. Supported values: Alignment.LEFT, Alignment.RIGHT, Alignment.CENTER and Alignment.JUSTIFY.

Returns

Table

this Table object.

SetTextColorInColumn(int, int)

Sets the color of the text in the specified column.

public Table SetTextColorInColumn(int index, int color)

Parameters

index int

the index of the specified column.

color int

the color specified as an integer.

Returns

Table

this Table object.

SetTextColorInRow(int, int)

Sets the color of the text in the specified row.

public Table SetTextColorInRow(int index, int color)

Parameters

index int

the index of the specified row.

color int

the color specified as an integer.

Returns

Table

this Table object.

SetVisibleColumns(params int[])

Keeps only the columns with the specified indexes.

public Table SetVisibleColumns(params int[] columns)

Parameters

columns int[]

Returns

Table

SetWidth(float)

Sets the width of the table. The columns share it by the percentages SetColumnWidthsInPercent gives them, whichever of the two is called first; without them, by the widths they have, as FitToWidth shares it.

public Table SetWidth(float width)

Parameters

width float

the width of the table.

Returns

Table

this Table object.

WrapAroundCellText()

Wraps around the text in all cells so it fits the column width. This method should be called after all calls to setColumnWidth and autoAdjustColumnWidths.

protected void WrapAroundCellText()