Client and backend. This class is shared: the same code is compiled into your app and into your server, so everything on this page works in both.

public final class PdfTable

  1. Object
  2. PdfTable

A table for PdfLayout. Columns share the available width in proportion to their weights; cells fill the rows left to right and wrap their text. A row that does not fit continues on the next page, and the header rows are repeated at the top of every page the table spans.

PdfDocument doc = new PdfDocument();
PdfLayout layout = new PdfLayout(doc, PdfPageSize.A4, 54);
PdfTable t = new PdfTable(3, 1, 1).setHeaderRows(1);
t.addCell(new PdfParagraph("Item", PdfFont.HELVETICA_BOLD, 10), 1, 0xeeeeee);
t.addCell(new PdfParagraph("Qty", PdfFont.HELVETICA_BOLD, 10), 1, 0xeeeeee);
t.addCell(new PdfParagraph("Price", PdfFont.HELVETICA_BOLD, 10), 1, 0xeeeeee);
t.addCell("Consulting").addCell("12").addCell("$1,200.00");
layout.add(t);

Constructors

public PdfTable(float... columnWeights)A table with one column per weight; each weight must be positive.

Methods

public PdfTable setHeaderRows(int rows)The number of leading rows that form the header; 0 by default.
public PdfTable setCellPadding(float points)The space between a cell’s border and its text; 4 points by default.
public PdfTable setBorder(float width, int rgb)The width and color of the cell borders; a width of 0 draws none.
public PdfTable setFont(PdfFont font, float size)The font of cells added as plain strings.
public PdfTable setSpaceAfter(float points)The space below the table; 8 points by default.
public PdfTable addCell(String text)Adds a cell of plain text in the table’s font.
public PdfTable addCell(PdfParagraph paragraph)Adds a cell holding paragraph.
public PdfTable addCell(PdfParagraph paragraph, int colspan, int backgroundRgb)Adds a cell spanning colspan columns, filled with backgroundRgb, or transparent when it is negative.

Inherited methods

Constructor details

PdfTable

public PdfTable(float... columnWeights)
A table with one column per weight; each weight must be positive.

Method details

setHeaderRows

public PdfTable setHeaderRows(int rows)
The number of leading rows that form the header; 0 by default.

setCellPadding

public PdfTable setCellPadding(float points)
The space between a cell’s border and its text; 4 points by default.

setBorder

public PdfTable setBorder(float width, int rgb)
The width and color of the cell borders; a width of 0 draws none.

setFont

public PdfTable setFont(PdfFont font, float size)
The font of cells added as plain strings.

setSpaceAfter

public PdfTable setSpaceAfter(float points)
The space below the table; 8 points by default.

addCell

public PdfTable addCell(String text)
Adds a cell of plain text in the table’s font.

addCell

public PdfTable addCell(PdfParagraph paragraph)
Adds a cell holding paragraph.

addCell

public PdfTable addCell(PdfParagraph paragraph, int colspan, int backgroundRgb)
Adds a cell spanning colspan columns, filled with backgroundRgb, or transparent when it is negative.