PdfTable Class

A table, drawn by PdfContentBuilder.DrawTable: columns with fixed, relative or automatic widths, rows of cells whose texts are broken into lines, borders, and header rows drawn again at the top of each page.

public sealed class PdfTable

Constructors

NameDescription
PdfTable()Initializes a new instance of the PdfTable class, without columns.
PdfTable(ReadOnlySpan<PdfTableColumn>)Initializes a new instance of the PdfTable class.

PdfTable overloads

PdfTable()

PdfTable.cs

Initializes a new instance of the PdfTable class, without columns.

public PdfTable()

PdfTable(ReadOnlySpan<PdfTableColumn>)

PdfTable.cs

Initializes a new instance of the PdfTable class.

public PdfTable(params scoped ReadOnlySpan<PdfTableColumn> columns)
Parameters
columns ReadOnlySpan<PdfTableColumn>
The columns of the table.

Properties

NameDescription
BorderColorGets or sets the color of the borders. The default is black.
BorderWidthGets or sets the width of the borders of the cells, in points, 0 or more: 0 draws no border. The default is 0.5.
CellPaddingGets or sets the space between the borders of a cell and its text, in points, 0 or more. The default is 4.
ColumnsGets the columns of the table, from the left.
FontGets or sets the font of the cells. The default is Helvetica.
FontSizeGets or sets the font size of the cells, more than 0. The default is 10.
HeaderRowCountGets or sets the number of rows at the start of PdfTable.Rows that are drawn again at the top of each continuation of the table. The default is 0.
HyphenatorGets or sets the hyphenator of the words that do not fit at the end of a line of a cell, or null to break the lines between the words only. The default is null.
LineHeightGets or sets the distance between the baselines of two lines of a cell, as a multiple of the font size, more than 0. The default is 1.2.
RowsGets the rows of the table, from the top: the header rows first.
TextColorGets or sets the color of the text of the cells, or null for the fill color of the graphics state. The default is null.

BorderColor

PdfTable.cs

Gets or sets the color of the borders. The default is black.

public PdfColor BorderColor { get; set; }

Property value

PdfColor

BorderWidth

PdfTable.cs

Gets or sets the width of the borders of the cells, in points, 0 or more: 0 draws no border. The default is 0.5.

public double BorderWidth { get; set; }

Property value

double

CellPadding

PdfTable.cs

Gets or sets the space between the borders of a cell and its text, in points, 0 or more. The default is 4.

public double CellPadding { get; set; }

Property value

double

Gets the columns of the table, from the left.

public IList<PdfTableColumn> Columns { get; }

Property value

IList<PdfTableColumn>

Gets or sets the font of the cells. The default is Helvetica.

public PdfFont Font { get; set; }

Property value

PdfFont

FontSize

PdfTable.cs

Gets or sets the font size of the cells, more than 0. The default is 10.

public double FontSize { get; set; }

Property value

double

HeaderRowCount

PdfTable.cs

Gets or sets the number of rows at the start of PdfTable.Rows that are drawn again at the top of each continuation of the table. The default is 0.

public int HeaderRowCount { get; set; }

Property value

int

Hyphenator

PdfTable.cs

Gets or sets the hyphenator of the words that do not fit at the end of a line of a cell, or null to break the lines between the words only. The default is null.

public IPdfHyphenator? Hyphenator { get; set; }

Property value

IPdfHyphenator?

LineHeight

PdfTable.cs

Gets or sets the distance between the baselines of two lines of a cell, as a multiple of the font size, more than 0. The default is 1.2.

public double LineHeight { get; set; }

Property value

double

Gets the rows of the table, from the top: the header rows first.

public IList<PdfTableRow> Rows { get; }

Property value

IList<PdfTableRow>

TextColor

PdfTable.cs

Gets or sets the color of the text of the cells, or null for the fill color of the graphics state. The default is null.

public PdfColor? TextColor { get; set; }

Property value

PdfColor?

Methods

NameDescription
AddHeaderRow(ReadOnlySpan<string>)Adds a header row after the header rows of the table, and increments PdfTable.HeaderRowCount.
AddRow(ReadOnlySpan<string>)Adds a row at the end of the table.
GetColumnWidths(double)Computes the widths of the columns of the table in a width.

AddHeaderRow(ReadOnlySpan<string>)

PdfTable.cs

Adds a header row after the header rows of the table, and increments PdfTable.HeaderRowCount.

public PdfTableRow AddHeaderRow(params scoped ReadOnlySpan<string> cells)

Parameters

cells ReadOnlySpan<string>
The texts of the cells, one per column.

Returns

PdfTableRow The row, to set its properties.

AddRow(ReadOnlySpan<string>)

PdfTable.cs

Adds a row at the end of the table.

public PdfTableRow AddRow(params scoped ReadOnlySpan<string> cells)

Parameters

cells ReadOnlySpan<string>
The texts of the cells, one per column.

Returns

PdfTableRow The row, to set its properties.

GetColumnWidths(double)

PdfTable.cs

Computes the widths of the columns of the table in a width.

public double[] GetColumnWidths(double availableWidth)

Parameters

availableWidth double
The width the table is drawn in.

Returns

double[] The width of each column, in points.

Exceptions

ArgumentException
A character of a cell has no glyph in its font.

Remarks

The fixed columns get their width. The automatic columns get the width of their widest paragraph, or less when the table would be wider than availableWidth: down to their widest word, then in proportion to it. The relative columns share the width left. The cells that span several columns do not count in the automatic widths.