title: PdfPageEventHelper in iTextSharp
body: <p>sorry if this was posted earlier</p>
  
  <p>I need to print list of expenses in a pdf document. the list may extend to any number of pages.</p>
  
  <p>i'm writing the list by iterating the datarow object.  One important thing is whenever the current page is going to end need to print the running total at the end of the page. i've wrote a class that implements PdfPageEventHandler as below</p>
  
  <pre><code>public class PaymentPageEventHandler : iTextSharp.text.pdf.PdfPageEventHelper
  {
      PdfContentByte cb;
  
      private string subTotal = "";
  
      public string GetSubtotal
      {
          set{
              value = subTotal;
          }
          get
          {
              return subTotal;
          }
      }
  
      public override void OnEndPage(PdfWriter writer, Document document)
      {
      //    base.OnEndPage(writer, document);
  
          cb = writer.DirectContent;
  
          float[] iOuterTblWidth = { 10, 40F, 8, 12, 10 }; column widths of the table.
  
          PdfPTable pdftbl = new PdfPTable(iOuterTblWidth);
          PdfPCell cell = new PdfPCell();
  
          cell.Colspan = 4;
          cell.AddElement(new Chunk("Sub-Total"));
          cell.HorizontalAlignment = 0;
          pdftbl.AddCell(cell);
  
          cell = new PdfPCell();
          cell.AddElement(new Chunk(GetSubtotal));
          cell.HorizontalAlignment = 2;
          pdftbl.AddCell(cell);
  
      }
  }
  </code></pre>
  
  <p>the onEndPAge event above tries to write two columns.  the above code gets called but the rows are not appearing in the pdf page.</p>
  
  <p>I'm calling the above class like below</p>
  
  <pre><code>PaymentPageEventHandler ppem = new PaymentPageEventHandler();
  ppem.GetSubtotal = "123"; // test value to print as running total
  writer.PageEvent = ppem; // assigning event to writer object
  </code></pre>
  
  <p>Should i call explicity the PdfContentByte variable cb to write. if so how should i write the cells to the pdf.</p>
  
  <p>can any one help me out on this.</p>