Tables are important when working with PDF documents. They provide great features for displaying information in a systematic manner. The
Aspose.PDF.Generator namespace contains classes named
Row which provides functionality for creating tables when generating PDF documents from scratch.
There has been a great demand from our customers for the ability to add tables to existing PDF documents. To support this functionality, we have introduced new classes named
Row under the
Add Table in Existing PDF Document
To add a table to an existing PDF file with Aspose.PDF for .NET, take the following steps:
- Load the source file.
- Initialize a table and set its columns and rows.
- Set table setting (we've set the borders).
- Populate table.
- Add the table to a page.
- Save the file.
The following code snippets show how to add text in an existing PDF file.
AutoFitToWindow property in ColumnAdjustmentType enumeration
Get Table Width
Sometimes, it is required to get table width dynamically. Aspose.PDF.Table class has a method GetWidth() for the purpose. For example, you have not set table columns width explicitly and set ColumnAdjustment to AutoFitToContent. In this case you can get table width as following.
Add SVG Object to Table Cell
Aspose.PDF for .NET supports the feature to add a table cell into a PDF file. While creating a table, it is possible to add text or images into the cells. Furthermore, the API also offers the feature to convert SVG files to PDF format. Using a combination of these features, it is possible to load an SVG image and add it into a table cell.
The following code snippet shows the steps for creating a table instance and adding an SVG image inside a table cell.
Add HTML Tags inside Table
Sometimes you can come up with a requirement to import database contents that have some HTML tags and then import the content to the Table object. When importing the content, it should be rendered the HTML tags accordingly inside PDF document. We have enhanced ImprotDataTable() method, in order to achieve such requirement as follows:
Insert a Page Break between rows of table
As a default behavior, when creating a table inside a PDF file, the table flows to subsequent pages when it reaches tables Bottom margin. However, we may have a requirement to forcefully insert page break when a certain number of rows are added for table. The following code snippet shows the steps to insert page break when 10 rows are added for the table.
Extract table border as Image
The page borders are path drawing operations. Therefore the Pdf->Html processing logic just performs drawing instructions and places the background behind the text. So, to repeat the logic, you have to process contents operators manually and draw the graphics yourself. Also please note that following code snippet might not work accurately for various PDF files but if you encounter any issue, please feel free to contact. This code was developed for specific PDF files. The following code snippet shows the steps to extract the table border as Image from PDF document.
Render Table on New Page
By default, paragraphs are added to a
Paragraphs collection. However, it is possible to render a table on a new page instead of directly after the previously added paragraph level object on the page.
Adding a Table
To render table on a new page, use the
IsInNewPage property in the
BaseParagraph class. The following code snippet shows how.