我有以下情况:我必须使用iTextSharp在我的PDF的页脚中创建一个圆角表,但我发现要做到这一点很困难。为什么我无法在此iText iTextSharp页脚表中获得圆角表格?
首先我必须创建一个名为PdfHeaderFooter,它扩展了PdfPageEventHelper iTextSharp的接口类。
在这个类我已经实现了的OnEndPage()方法是创建在所有页面的末尾页脚,这是我的代码:
// Write on end of each page
public override void OnEndPage(PdfWriter writer, Document document)
{
base.OnEndPage(writer, document);
PdfPTable tabFot = new PdfPTable(new float[] { 1F });
tabFot.TotalWidth = 300F;
tabFot.DefaultCell.Border = PdfPCell.NO_BORDER;
tabFot.DefaultCell.CellEvent = new RoundedBorder();
PdfPCell cell;
cell = new PdfPCell(new Phrase("Footer"));
tabFot.AddCell(cell);
tabFot.WriteSelectedRows(0, -1, 150, document.Bottom, writer.DirectContent);
}
正如你在代码中看到我创建表名为TabFoot即300px wisth并包含单个列。我还将此表单元的单元格事件处理程序设置为RoundBorder对象。
这是我RoundBorder类的代码:
class RoundedBorder : IPdfPCellEvent
{
public void CellLayout(PdfPCell cell, iTextSharp.text.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();
}
}
的问题是,我的工作方案和PDF生成,但在页脚中的表没有圆角但经典的方角落,我得到这样的结果:
为什么?我错过了什么?我能做些什么来解决?
TNX
当创建自己的PdfPCell实例时,是否有任何方法可以使表格而不是每个单元格的边框四舍五入? –
是的,这是使用表事件而不是单元事件完成的。 –