c# - 如何使用 iText\iTextSharp 创建圆角表?

标签 c# pdf pdf-generation itext

<分区>

我必须创建一个带有圆角的表格,类似于:

enter image description here

我可以用 iTextSharp 做吗?

最佳答案

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

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

确保您没有向单元格添加任何“自动”边框,而是在单元格事件中自己绘制边框:

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

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();
  }
}

您当然可以微调值 1.5、3 和 4 以获得不同的效果。

关于c# - 如何使用 iText\iTextSharp 创建圆角表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23650957/

相关文章:

c# - 列表框项目方向为水平

javascript - 在 google chrome 中显示 Pdf 文件的 Angularjs 代码不起作用,但适用于 Firefox

c# - (以编程方式)比较 PDF 的可靠方法?

c# - Update 1 RC 降级为 CTP 后,LINQ to Entities 仅支持转换 EDM 基元或枚举类型

c# - 如何在 Main 中启动公共(public)方法?

pdf - 是否可以创建不可见的 XFA 表单?

c# - 使用 ExpertPDF/Aspose.Pdf 组件将 Html 转换为 PDF 需要很长时间

pdf - 在 Angular 2 中生成 pdf

c# - 是否有更有效的方法来编写使用 DateTime 值的 IF 语句?

python - 如何使用 Python 或 R 将 Excel 中带有替代文本的图形导出为 PDF?