Бинго! Класс PdfPageEventHandler работал для меня.
Я использовал PdfPageEventHelper, переопределяющий метод OnEndPage:
class _events : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document document)
{
PdfPTable table = new PdfPTable(1);
//table.WidthPercentage = 100; //PdfPTable.writeselectedrows below didn't like this
table.TotalWidth = document.PageSize.Width - document.LeftMargin - document.RightMargin; //this centers [table]
PdfPTable table2 = new PdfPTable(2);
//logo
PdfPCell cell2 = new PdfPCell(Image.GetInstance(@"C:\path\to\file.gif"));
cell2.Colspan = 2;
table2.AddCell(cell2);
//title
cell2 = new PdfPCell(new Phrase("\nTITLE", new Font(Font.HELVETICA, 16, Font.BOLD | Font.UNDERLINE)));
cell2.HorizontalAlignment = Element.ALIGN_CENTER;
cell2.Colspan = 2;
table2.AddCell(cell2);
PdfPCell cell = new PdfPCell(table2);
table.AddCell(cell);
table.WriteSelectedRows(0, -1, document.LeftMargin, document.PageSize.Height - 36, writer.DirectContent);
}
}
затем сборка pdf
Document document = new Document(PageSize.A4, 36, 36, 36 + <height of table>, 36); // note height should be set here
_events e = new _events();
PdfWriter pw = PdfWriter.GetInstance(document, new FileStream("TableTest.pdf", FileMode.Create));
pw.PageEvent = e;
document.Open();
for(int i=0;i<100;i++)
{
document.Add(new Phrase("TESTING\n"));
}
document.Close();