code: @Override
     public final void onOpenDocument(PdfWriter writer, Document document) {
        super.onOpenDocument(writer, document);
        template = writer.getDirectContent().createTemplate(document.getPageSize().getWidth(), document.getPageSize().getHeight());
        if (!getSettings().containsKey(PAGEFOOTERSTYLEKEY)) {
           getSettings().put(PAGEFOOTERSTYLEKEY, PAGEFOOTERSTYLE);
        }
        if (!getSettings().containsKey(PAGEFOOTERTABLEKEY)) {
           float tot = ItextHelper.ptsToMm(document.getPageSize().getWidth() - document.leftMargin() - document.rightMargin());
           getSettings().put(PAGEFOOTERTABLEKEY, new StringBuilder("Table(columns=3,widths=")
               .append(Math.round(tot * getSettings().getFloatProperty(0.85f, "footerleftwidthpercentage"))).append('|')
               .append(Math.round(tot * getSettings().getFloatProperty(0.14f, "footermiddlewidthpercentage"))).append('|')
               .append(Math.round(tot * getSettings().getFloatProperty(0.01f, "footerrightwidthpercentage"))).append(')').toString()
           );
        }
     }
docs: prepares template for printing header and footer
  
  @param writer
  @param document