How to create a rounded corner table using iText\iTextSharp? [duplicate]

谁说胖子不能爱 提交于 2019-12-19 10:25:40

问题


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

Can I do it with iTextSharp?


回答1:


This is done using cell events.

See the Calendar example from my book (Java / C#).

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];
    cb.RoundRectangle(
      rect.Left + 1.5f, 
      rect.Bottom + 1.5f, 
      rect.Width - 3,
      rect.Height - 3, 4
    );
    cb.Stroke();
  }
}

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



来源:https://stackoverflow.com/questions/23650957/how-to-create-a-rounded-corner-table-using-itext-itextsharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!