C# 仅在Itextshrp的最后一页添加页脚

C# 仅在Itextshrp的最后一页添加页脚,c#,itextsharp,C#,Itextsharp,我只想在最后一页显示页脚,所以我使用了onCloseDocument方法 public void onCloseDocument(PdfWriter writer, Document document) 我的代码是 public override void OnCloseDocument(PdfWriter writer, Document document) { base.OnCloseDocument(writer,

我只想在最后一页显示页脚,所以我使用了onCloseDocument方法

public void onCloseDocument(PdfWriter writer,
                            Document document)
我的代码是

public override void OnCloseDocument(PdfWriter writer, Document document)
{
        base.OnCloseDocument(writer, document);
        PdfPTable tabFot = new PdfPTable(1);
        tabFot.DefaultCell.Border = PdfPCell.NO_BORDER;
        PdfPCell cell;
        tabFot.TotalWidth = 50F;

        cell = new PdfPCell(new Phrase("footer text"));
        cell.BorderWidthBottom = 0f;
        cell.BorderWidthLeft = 0f;
        cell.BorderWidthTop = 0f;
        cell.BorderWidthRight = 0f;
        tabFot.AddCell(cell);
        tabFot.WriteSelectedRows(0, -1, 300, 50, writer.DirectContent);
    }
但这对我不起作用。我想因为这个方法被调用,页码等于最后一页加一


任何人都可以帮助我如何完成此任务。

为什么不在关闭(完成创建)文档之前创建页脚?要实现这一点,您根本不需要
OnCloseDocument
。为什么不在关闭(完成创建)文档之前创建页脚呢?要实现这一点,您根本不需要关闭文档。