Skip to main content
Skip table of contents

How to create a table with rounded corners?

How do I do this?

I have to create a table having rounded corners, something like it:

Cell with rounded borderPosted on StackOverflow on May 14, 2014 by AndreaNobili

In iText 7 this is done using cell renderers. You should set such renderer for your cell:

cell.setNextRenderer(new RoundedBorderCellRenderer(cell));

The RoundedBorderCellRenderer class would then look like this:

private class RoundedBorderCellRenderer extends CellRenderer {
    public RoundedBorderCellRenderer(Cell modelElement) {
        super(modelElement);
    }

    @Override
    public void draw(DrawContext drawContext) {
        drawContext.getCanvas().roundRectangle(getOccupiedAreaBBox().getX() + 1.5f, getOccupiedAreaBBox().getY() + 1.5f,
                getOccupiedAreaBBox().getWidth() - 3, getOccupiedAreaBBox().getHeight() - 3, 4);
        drawContext.getCanvas().stroke();
        super.draw(drawContext);
    }
}

You can of course fine-tune the values 1.5, 3 and 4 to get different effects.

Click How to create a table with rounded corners? if you want to see how to answer this question in iText 5.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.