Elements
How elements work and how to add them to a page.
Elements are the building blocks of a document. Every visible thing on a page, whether it is a line of text, a table row, an image, or a spacer, is an element.
Adding elements
Inside a content(), header(), or footer() callback you receive a ColumnElement. Call .item() on it to add children fluently:
content(c -> {
c.item().text("A paragraph of text");
c.item().spacer(12);
c.item().row(row -> {
row.fillColumn(col -> col.text("Left"));
row.fillColumn(col -> col.text("Right"));
});
c.item().table(table -> { /* ... */ });
})You can also pass a pre-built element directly to .add():
c.add(new SeparatorElement().color(Colors.GRAY_400));
c.add(ImageElement.ofResource("/logo.svg").width(120));Element types
Text
TextElement and RichTextElement for plain and mixed-style text.
Layout
Column, Row, Grid, Container, and Stack for arranging content.
Table
TableElement with typed columns, headers, rows, and per-cell styling.
Media
Images, QR codes, and barcodes.
Structural
Spacers, separators, and page breaks.
Form
Input fields and hyperlinks.
How measuring and rendering work
Every element has three internal methods that Kawa calls during generation:
measure(ctx)returns the height the element needs for the available width. Kawa uses this to decide whether the element fits on the current page.render(ctx, renderCtx)draws the element into the PDF.renderSlice(...)draws a partial portion when the element needs to split across a page break. Layout elements likeTableElementandColumnElementsupport this.
You never call these methods yourself.