Add simple table in PDF using iText

iText provides PdfPTable that is used while working with tables in pdf. Lets see examples on how to add simple table in PDF using iText with some examples.

Important class : com.itextpdf.text.pdf.PdfPTable

You can use the following methods to create simple table and add data
a) PdfPTable(int numColumns) Constructs a PdfPTable with numColumns columns.
b) addCell(String text) Adds data to the cell
c) setHeaderRows(int headerRows) Sets the number of the top rows that constitute the header. This header has only meaning if the table is added to Document and the table crosses pages.

Example

In the below example we will use the above methods to create a simple table with a header and some data

Output
Add simple table in PDF using iText

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn