Tables: The Workhorse Element

Harry · 24 Sep 2026 · 1 views
Log in to track your progress and mark lessons complete.

Basic Table

import com.itextpdf.layout.element.*;

Table table = new Table(3); // 3 columns
table.addCell("Name");
table.addCell("Dept");
table.addCell("Salary");
table.addCell("Nisha");
table.addCell("IT");
table.addCell("75000");
document.add(table);

Three column employee table

Header Rows and Column Widths

Table t = new Table(new float[]{3, 2, 2}); // relative widths
t.addHeaderCell("Name");
t.addHeaderCell("Dept");
t.addHeaderCell("Salary");
// ... data cells ...

Header cells repeat automatically on every page the table spans. Style headers with a background: cell.setBackgroundColor(new DeviceRgb(15, 118, 110)).

Share this post:

Comments (0)

Please login or register to comment.

Create a free account to keep reading

You've enjoyed a free tutorial! Register (it's free) to unlock every tutorial, track your progress and save code.

or sign in with your account

Already have an account? Log in