Table
The Table class helps you easily create tabular data content. All you need to do is define the table content and pass a Table instance to a FixedContentEditor or a RadFixedDocumentEditor. From then on, these editors are responsible for positioning, measuring, drawing and splitting the table onto pages.
This article aims to present the table-related API in RadPdfProcessing. It contains the following sections:
Defining Table Content
Each table contains a series of TableRow instances each of which contains a series of TableCell instances. In order to define a simple table, you need to generate the table cells and add some content to them.
Example 1 shows how to generate a simple table with two rows and three columns with some sample text in each table cell.
Example 1: Create simple table
The result table is shown in Figure 1.
Figure 1: Table
Using DefaultCellProperties
If you want to apply default styling to all the cells in a table, you can use Table's DefaultCellProperties property. This allows to easily modify the default cell presentation.
- Padding: Specifies the distances between the inner cell border contour and the cell content.
- Borders: Property of type TableCellBorders, which specifies the borders of a single cell. The available borders are left, right, top, bottom, diagonal up and diagonal down.
- Background: Specifies the background of the cell.
Еxample 2 shows how to use the DefaultCellProperties of a table
Example 2: Use DefaultCellProperties of Table
The result of the snippet in Example 2 is demonstrated on Figure 2.
Figure 2: Result of DefaultCellProperties modification
Modifying a Table
There are several factors that affect tables measuring calculations. Some of them are listed and explained bellow:
Margin: Specifies the distances between the table borders outline and the rest of the document's content.
Padding: Set through the TableCell's Padding property, it specifies the distances between cell borders inner contour and the cell content.
-
LayoutType: Specifies the algorithm, which shall be used to layout table contents. There are two options available in the TableLayoutType enumeration:
- AutoFit – The table width fits the content unless the needed width is bigger than the available measuring width.
- FixedWidth – The table width always fits the available measuring width.
HorizontalAlignment: Specifies the alignment of the table inside the page.
BorderSpacing: Specifies the distance between all the borders in the table. This distance is measured differently depending on the BorderCollapse option.
-
BorderCollapse: Specifies the way the border spacing calculations should be done. There are two options:
- Collapse: The distance between borders is measured from the middle lines of the borders
- Separate: The distance between borders is measured from the outer border contour.
Example 3 demonstrates how border calculations occur with different BorderCollapse option. The code in this example creates an empty table and sets default cell padding and red table border with thickness 10 to it.
Example 3: Create table with red border
Example 4 adds a single row with two cells to the table from Example 3. The first cell has a green border with thickness 5 while the second cell has a blue border with thickness 3.
Example 4: Add green and blue cells
Figure 3 shows the table from Example 3 and 4 with BorderCollapse property set to Collapse - all borders are drawn so that their middle lines coincide.
Example 5: Collapse border
Figure 3: Collapsed border
Figure 4 shows the same table with BorderCollapse property set to Separate - all borders are drawn so that their outer contour coincide.
Example 6: Separate border
Figure 4: Separated border
Drawing Table with RadFixedDocumentEditor
When a table is generated, it could be inserted in the PDF document using the RadFixedDocumentEditor's InsertTable() method. This way the table is inserted in the document and split onto pages if necessary.
Example 7 generates a simple table with two cells.
Example 7: Create table
Example 8 inserts the table from Example 7 in a RadFixedDocumentEditor and specifies the table layout type to AutoFit.
Example 8: Insert AutoFit table
The result is that the table width is exactly as needed for fitting the cells content as visible in Figure 5.
Figure 5: AutoFit table
Specifying FixedWidth layout option produces different results.
Example 9: Insert FixedWidth table
Figure 6: FixedWidth table
Drawing Table with FixedContentEditor
When in need of more customization options, you can use the DrawTable() method of FixedContentEditor instead of RadFixedDocumentEditor.
Example 10 shows how to draw a rotated table with the help of FixedContentEditor.
Example 10: Draw rotated table
As a result, on Figure 7 you can see a 45-degree rotated table similar to the one on Figure 5.
Figure 7: FixedWidth table
Supported Border Styles
As of Q3 2024, along with the BorderStyle.Single, RadPdfProcessing offers Dotted, Dashed, and DashSmallGap border styles. With this update, the Dotted, Dashed, DashSmallGap, and Thick border lines are now exported from RadFlowDocument to RadFixedDocument as well.
BorderStyle | Border Design |
---|---|
Single | ![]() |
Dotted | ![]() |
Dashed | ![]() |
DashSmallGap | ![]() |