title: PdfPageEventHelper in iText
body: <p>I am creating a pdf where the title of each pdf page would be customized based on the current page number. For example, in the 1st page the title is "First Page", and in the 2nd page the title is "Second Page", and so on...</p>
  
  <p>What we do now is we add the title to a PdfPTable, then we add a lot of other stuff to the PdfPTable as well, so this PdfPTable contains several pages of data. Finally we add this large PdfPTable object to document. Now we want to use the onStartPage() method in PdfPageEventHelper to get the current page number so that we can customize the title for each page. </p>
  
  <p>The problem is onStartPage() does not trigger until we add that large PdfPTable object to the document, which means we cannot make the resource bundle to load different key values before the PdfPTable object is added to the document, right? Any suggestion to realize this?</p>
  
  <p>--------------------we have codes like below-------------------------------------</p>
  
  <pre><code>  Phrase title = new Phrase();
    title.add(new Chunk(bundle.getString(pdfNewPageEventHandler.getKey()), headerFont));
    PdfPCell cell = new PdfPCell(new Paragraph(
              new Phrase(title)));
    .........
    PdfPTable table = new PdfPTable(tableSize);
    table.addCell(cell);
    .........
    document.add(table);
  
  
  
  
  private class PdfNewPageEventHandler extends PdfPageEventHelper {
  
      private int currentPageNum = 0;
      private String key;
  
      @Override
      public void onStartPage(PdfWriter writer, Document document) {
  
          currentPageNum = currentPageNum + 1;
  
          if (currentPageNum == 1) {
              key = "firstPage";
          } 
          else if (currentPageNum == 2) {
              key = "secondPage";
          }
  
      }
  
      public String getKey() {
          return key;
      }
  
  }
  </code></pre>