title: How to add text as a header or footer?
body: <p>I'm creating a pdf with iText 5 and want to add a footer. I did everything like the book "iText in action" in Chapter 14 says. </p>
  
  <p>There are no errors but the footer doesn't show up.
  Can somebody tell me what I'm doing wrong?</p>
  
  <p>My code:</p>
  
  <pre><code>public class PdfBuilder {
  
      private Document document;
  
      public void newDocument(String file) {
          document = new Document(PageSize.A4);
          writer = PdfWriter.getInstance(document, new FileOutputStream(file));
          MyFooter footerEvent = new MyFooter();
          writer.setPageEvent(footerEvent);
          document.open();
  
          ...
  
          document.close();
          writer.flush();
          writer.close();
      }
  
      class MyFooter extends PdfPageEventHelper {
  
      public void onEndPage(PdfWriter writer, Document document) {
          PdfContentByte cb = writer.getDirectContent();
          ColumnText.showTextAligned(cb, Element.ALIGN_CENTER, footer(), (document.right() - document.left()) / 2
                  + document.leftMargin(), document.top() + 10, 0);
  
      }
  
      private Phrase footer() {
          Font ffont = new Font(Font.FontFamily.UNDEFINED, 5, Font.ITALIC);
          Phrase p = new Phrase("this is a footer");
          return p;
      }
  }
  </code></pre>