Flow Documents – part 3 – pdf tables

Support for pdf tables is available in XFINIUM.PDF library through the flow content API and PdfFlowTableContentclass.

The table

To add a table to a pdf file you create a PdfFlowTableContent object, set up its properties and content and add the table object to the flow document.
When a table object is created, its number of columns must be specified. In this situation all columns have the same width. Alternatively the table object can be created with an array of column objects (instances of PdfFlowTableColumn class) specifying the distinct properties for each column.
The table takes all available space on horizontal. If the sum of column widths does not match the available width, the last column is adjusted to fill the available space.
The table’s Border property specifies the border to be drawn around cells. This border is used if the cells do no specify an explicit border.
The DefaultCell property specifies the default properties when cells are constructed automatically based on the type of input data (example 1).

The row

The table data is stored in a collection of rows. The Rows property (of type PdfFlowTableRowCollection) lets you add or remove rows from a table.
A row can have a minimum height. The row height can grow over this value if the content requires, but it cannot go below this value. When a row fits partially at the bottom of the page, its content is split in 2 if the available space is greater than row’s minimum height.

The cell

Each row has a collection of Cells (of type PdfFlowTableCellCollection). This collection lets you add or remove cells from a row. If the number of cells in a row is greater than number of table columns, the cells at the end are ignored.
If the number of cells in a row is less than number of table columns, empty placeholders are generated to fill the remaining columns.

Multiple cell types are supported for pdf tables:
– string cells (PdfFlowTableStringCell) – they are used to display string content. Strings are displayed on a single line by default unless the Multiline property is set to true.
– image cells (PdfFlowTableImageCell) – they are used to display images. Depending on cell size and image size, the image can be aligned left/center/right on horizontal and top/middle/bottom on vertical.
– form XObject cells (PdfFlowTableFormXObjectCell) – they are used to display form XObjects. Depending on cell size and XObject size, the XObject can be aligned left/center/right on horizontal and top/middle/bottom on vertical.
– composite cells (PdfFlowTableCompositeCell) – they are used to combine multiple types of flow content. Their Content property is a collection of flow content objects.

All cells share a common set of properties:
Background – a brush that specifies how to fill the cell background. If the property is not set explicitly, the row’s background is used.
InnerMargins – left/right/top/bottom margins inside the cell area. Cell content is placed only inside these margins.
HorizontalAlign – alignment of cell content on horizontal. If not set, the column horizontal alignment is used.
VerticalAlign – alignment of cell content on vertical. If not set, the column vertical alignment is used.
Borders – specifies how the left/right/top/bottom borders are drawn. If the property is not set explicitly, the tables’s Border is used.
RowSpan – the number of rows the cell spans over. If the RowSpan is greater than number of available rows, then only the available rows are used.
ColSpan – the number of columns the cell spans over. If the ColSpan is greater than number of columns, then it is limited to the number of columns.

Examples:

  1. Simple 3×3 table. PdfFlowTableContent.DefaultCell is a string cell by default, and AddRowWithCells method below creates cells based on its properties.
    C#:

    VB.NET:
  2. 3×3 table, each cell is built separately.
    C#:

    VB.NET:

These samples included in XFINIUM.PDF install kit provide additional information about working with PDF tables: Invoice, SimpleTable, TableCellSpans, TableGroups.

Leave a Reply