C# 如何使用itextsharp pdf添加页脚(带变量/类)

C# 如何使用itextsharp pdf添加页脚(带变量/类),c#,pdf,itext,C#,Pdf,Itext,我有这个代码,我想添加一个表作为页脚。但问题是我无法传递变量: Document doc = new Document(); doc.AddTitle("e-8D Report_" + report.OSIE8DNO + ".pdf"); PdfWriter writer = PdfWriter.GetInstance(doc, fs); doc.SetPageSize(PageSize.A4); doc.SetMargins(18f, 18f, 18f

我有这个代码,我想添加一个表作为页脚。但问题是我无法传递变量:

Document doc = new Document();
doc.AddTitle("e-8D Report_" + report.OSIE8DNO + ".pdf");
PdfWriter writer = PdfWriter.GetInstance(doc, fs);

doc.SetPageSize(PageSize.A4);
doc.SetMargins(18f, 18f, 18f, 18f); // 0.25 inch margins

doc.Open();

PdfPTable table = new PdfPTable(10)
{
       WidthPercentage = 100,
       LockedWidth = true,
       TotalWidth = 560f
};
float[] widths = new float[] { 32f, 73f, 70f, 70f, 70f, 70f, 70f, 70f, 73f, 32f };
table.SetWidths(widths);

// rest of the document
// ...
// rest of the document

// Below is the part that I want to add as footer

#region Footer
// left margin
cell = new PdfPCell(new Phrase(" ", font6))
{
      Border = Rectangle.NO_BORDER
};
table.AddCell(cell);

cell = new PdfPCell(new Phrase("Reviewed & Approved by :", font6))
{
      Colspan = 4,
      BackgroundColor = bgBlue,
      HorizontalAlignment = Element.ALIGN_LEFT,
      Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER
};
table.AddCell(cell);

cell = new PdfPCell(new Phrase("For document approval by email, no Manual / e-Signature required &", font2))
{
       Colspan = 4,
       BackgroundColor = bgBlue,
       HorizontalAlignment = Element.ALIGN_LEFT,
       Border = Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER
};
table.AddCell(cell);

// right margin
cell = new PdfPCell(new Phrase(" ", font6))
{
       Border = Rectangle.NO_BORDER
};
table.AddCell(cell);

// the rest of the cell
//...
// the rest of the cell

#endregion

doc.Add(table);
//writer.PageEvent = new PDFFooter();
doc.Close();
使用此变量,我无法使用此源的PdfPageEventHelper生成页脚:


请帮助

已经得到了答案。我将参数添加到PdfPageEventHelper类:

public PdfPTable footer { get; set; }

public override void OnEndPage(PdfWriter writer, Document document)
{
     base.OnEndPage(writer, document);
     document.Add(footer);
}
并从页面调用(首先在页面上创建完整的表):

writer.PageEvent = new PDFHeaderFooter() { footer = table };