如何使用iText\iTextSharp创建圆角桌? [英] How to create a rounded corner table using iText\iTextSharp?
本文介绍了如何使用iText\iTextSharp创建圆角桌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须创建一个圆角的桌子,类似于:
I have to create a table having rounded corners, something like it:
我可以用iTextSharp进行吗?
Can I do it with iTextSharp?
推荐答案
这是使用单元格事件完成的。
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();
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获得不同的效果。
You can of course fine-tune the values 1.5, 3 and 4 to get different effects.
这篇关于如何使用iText\iTextSharp创建圆角桌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文