<分区>
我必须创建一个带有圆角的表格,类似于:
我可以用 iTextSharp 做吗?
标签 c# pdf pdf-generation itext
<分区>
我必须创建一个带有圆角的表格,类似于:
我可以用 iTextSharp 做吗?
最佳答案
这是使用单元格事件完成的。
确保您没有向单元格添加任何“自动”边框,而是在单元格事件中自己绘制边框:
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/