Title

Sunday, 18 January 2015

I Text Sharp how to repeat header and footer


how to repeat report header and footer in everypage by itextsharp using PageEvent? I found the report header is not repeat if we add

pdfWriter.PageEvent = new MarginalHelper();       public class MarginalHelper: PdfPageEventHelper  {   public override void OnStartPage(PdfWriter pdfWriter, Document document)   {   new HeaderInformation(pdfWriter);   }     public override void OnEndPage(PdfWriter pdfWriter, Document doc)   {       ReportFooter(pdfWriter.DirectContent);   }}

Header wont appear in the first page. Anyone know a solution for this? i do not want to use a table for headers .

Answer

As documented, you should never add content in the OnStartPage() method, only in the OnEndPage() method. In other words: move new HeaderInformation(pdfWriter); to the OnEndPage() method. Also make sure that you declare the PageEvent before opening the document.

No comments:

Post a Comment