title: ItextSharp : How to set dynamic header using ITextsharp. C#.Net
body: <p>I am creating PDF with 3 pages, all 3 pages should have 3 different headers. I came across one example in documentation <a href="http://developers.itextpdf.com/examples/page-events/page-events-headers-and-footers#693-variableheader.java" rel="nofollow noreferrer"> VaraibleHeader. </a> However its not working below is my code.</p>
  
  <pre><code>  public class ReportPdfHeaderFooter : PdfPageEventHelper
    {
          public void SetHeader(string header)
          {
              this._header = header;
          }
  
          public override void OnEndPage(PdfWriter writer, Document document)
          {
              base.OnEndPage(writer, document);
              PdfPTable table = new PdfPTable(1);
              table.AddCell(title);
              footer.WriteSelectedRows(0, -1, Pdf.MarginLeft, document.Bottom, writer.DirectContent);
           }
     }
  
    public CreatePdf()
    {
         private Document _doc;
         private MemoryStream _memStream;
         private PdfWriter _pdfWriter;
         this._doc = new Document();
         this._memStream = new MemoryStream();
         this._pdfWriter = PdfWriter.GetInstance(this._doc, _memStream);
         var reportPdfHeaderFooter = new ReportPdfHeaderFooter();
  
         _pdfWriter.PageEvent = headerFooter;
         reportPdfHeaderFooter.SetHeader("Header 1");
         _doc.Open();
         reportPdfHeaderFooter.SetHeader("Header 2");
         _doc.NewPage();
         _doc.Close();
   }
  </code></pre>
  
  <p>I have done exactly whatever mentioned in the documentation, still i am getting Header 2 as title in both the pages.</p>