How to create a table with rounded corners?

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

This is done using cell events.

Make sure that you don't add any "automated" borders to the cell, but draw the borders yourself in a cell event:

table.DefaultCell.Border  = PdfPCell.NO_BORDER;
table.DefaultCell.CellEvent = new RoundedBorder();

The RoundedBorder class would then look like this:

class RoundedBorder : IPdfPCellEvent {
  public void CellLayout(PdfPCell cell, Rectangle rect, PdfContentByte[] canvas) {
    PdfContentByte cb = canvas[PdfPTable.BACKGROUNDCANVAS];
      rect.Left + 1.5f,
      rect.Bottom + 1.5f,
      rect.Width - 3,
      rect.Height - 3, 4

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

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

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