Reputation: 21
I am creating a pdf file using itextsharp. I want to add header and footer for each page in the pdf document. Can anyone tell me how can I do this?
I am using itext 5.2.0 In this, I am unable to find the option to use HeadeFooter class, which is available in the earlier versions.
Thanks in advance..
Upvotes: 2
Views: 24534
Reputation: 339
Please use this code.
public partial class Footer : PdfPageEventHelper
{
public override void OnEndPage(PdfWriter writer, Document doc)
{
Paragraph footer= new Paragraph("THANK YOU", FontFactory.GetFont(FontFactory.TIMES, 10, iTextSharp.text.Font.NORMAL));
footer.Alignment = Element.ALIGN_RIGHT;
PdfPTable footerTbl = new PdfPTable(1);
footerTbl.TotalWidth = 300;
footerTbl.HorizontalAlignment = Element.ALIGN_CENTER;
PdfPCell cell = new PdfPCell(footer);
cell.Border = 0;
cell.PaddingLeft = 10;
footerTbl.AddCell(cell);
footerTbl.WriteSelectedRows(0, -1, 415, 30, writer.DirectContent);
}
}
please check my blog for more details http://gopalkaroli.blogspot.in/2011/11/how-to-add-header-and-footer-on-pdf.html
Upvotes: 7
Reputation: 3439
For iTextSharp version 5+, Header/Footer property has been removed. Now this can be done by us PageEventHandler
class. Though it's not strait forward now but the upside is that now you can add more than just plan text in header and footer. Please check this link for complete workout of header/footer and more in iTextSharp.
Upvotes: -1