Add Table in Existing PDF Document

Tables are important when working with PDF documents. They provide great features for displaying information in a systematic manner. The com.aspose.pdf package contains classes named Table, Cell and Row which provide functionality for creating tables when generating PDF documents from scratch.

In this article, we show how to use these new classes to add a table to an existing PDF.

Adding a Table

To add a table to an existing PDF file with Aspose.PDF for Java, take the following steps:

  1. Load the source file.
  2. Initialize a table and set its columns and rows.
  3. Set table setting (we’ve set the borders).
  4. Populate table.
  5. Add the table to a page.
  6. Save the file.

The following code snippets show how to add table in an existing PDF file.

AutoFitToWindow property in ColumnAdjustmentType enumeration

Hide Spanned Cell Borders

While adding cells to a table, the spanned cell borders may show up when they break to another row. Such spanned borders can be made hidden as shown in the following code sample.