如何使用iText\iTextSharp创建圆角桌?

And*_*ili 2 c# pdf pdf-generation itext itextsharp

我必须创建一个圆角的桌子,类似于:

在此输入图像描述

我可以用iTextSharp做到吗?

Bru*_*gie 8

这是使用单元格事件完成的.

请参阅我的书中的日历示例(Java/C#).

确保不向单元格添加任何"自动"边框,但在单元格事件中自己绘制边框:

table.DefaultCell.Border  = PdfPCell.NO_BORDER;
table.DefaultCell.CellEvent = new RoundedBorder();
Run Code Online (Sandbox Code Playgroud)

这个RoundedBorder类看起来像这样:

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();
  }
}
Run Code Online (Sandbox Code Playgroud)

您当然可以微调值1.​​5,3和4以获得不同的效果.