Kawa
Elements

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

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 like TableElement and ColumnElement support this.

You never call these methods yourself.

On this page