我正在创建一个 pdf 文档。有一个 PdfPTable,其中一些行将在每一页中重复。我想要的是在每一页的表格单元格中添加页码。
我尝试在 PdfPageEventHelper 中渲染单元格并在 onEndPage() 中写入表,但页码计数没有增加,并且在非常 page 中始终为 1。
我怎样才能做到这一点?
[更新]
我渲染了表 OnStartPage() 而不是构造函数。我使用 writer.PageNumber 作为 pageCount。现在增加了页码,但表格在每一页中一次又一次地出现。
public class itsEventsHandler : PdfPageEventHelper
{
int pageCount;
protected PdfPTable tblAccInfo = new PdfPTable(3);
public itsEventsHandler()
{
}
public override void OnStartPage(PdfWriter writer, Document document)
{
pageCount = writer.PageNumber;
this.BuildBorderCell(tblAccInfo, "A/C No.", boldFont);
this.BuildBorderCell(tblAccInfo, "External Doc No.", boldFont);
this.BuildBorderCell(tblAccInfo, "PAGE", boldFont);
this.BuildBorderCell(tblAccInfo, accountNo, titleFont);
this.BuildBorderCell(tblAccInfo, docNo, titleFont);
this.BuildBorderCell(tblAccInfo, pageCount.ToString(), titleFont);
}
public override void OnEndPage(PdfWriter writer, Document document)
{
tblAccInfo.WriteSelectedRows(0, -1, document.LeftMargin + 53f,
document.PageSize.Height - 250f, writer.DirectContent);
}
}
我希望页码在每一页的表格单元格中。