How to create a table with rounded corners?

I have to create a table having rounded corners, something like it: Can I do it with iTextSharp? Posted on StackOverflow on May 14, 2014 by AndreaNobili In iText 7 this is done using

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

Cell with rounded border

Can I do it with iTextSharp?

Posted 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 this link if you want to see how to answer this question in iText 5.


Share this article

Ready to use iText?

Try our iText 7 Library and add-ons FREE for 30 days. Test your proof of concept, and see if our solution is right for you.

Get my FREE trial
Contact

Still have questions? 

We're happy to answer your questions. Reach out to us and we'll get back to you shortly.

Contact us
Stay updated

Join 11,000+ subscribers and become an iText PDF expert by staying up to date with our new products, updates, tips, technical solutions and happenings.

Subscribe Now