title: Getting total pages in pdf using itext and increasing height of the image in the header
body: <p>This is the code I have </p>
  
  <pre><code>&lt;% 
  Class.forName("com.mysql.jdbc.Driver");
  class HeaderAndFooter extends PdfPageEventHelper {
     private String name = "";
     protected Phrase footer;
     protected Phrase header;
     PdfTemplate total;
     Font headerFont = new Font(FontFamily.COURIER, 13, Font.UNDERLINE);
     Font footerFont = new Font(FontFamily.HELVETICA, 11, Font.BOLD);
     Font footerFont1 = new Font(FontFamily.TIMES_ROMAN, 9,Font.BOLDITALIC);
     String date1;
     public HeaderAndFooter(String name) {
      super();
      this.name = name;
      header = new Phrase("***** Header *****");
      footer = new Phrase("**** Footer ****");
    }
  
  
    @Override
     public void onEndPage(PdfWriter writer, Document document) {
       PdfContentByte cb = writer.getDirectContent();
       String headerContent =name;
       String footerContent = headerContent;
       String log="C:/Users/Desktop/671.png";
       float gap = (document.getPageSize().getWidth())/ 30;
       float hei=(document.getPageSize().getHeight() - 60);
       Image img1=null;
       try{
           String message="";
           Connection con=null;
           Statement st;
  
           try{
                   con = DriverManager.getConnection("jdbc:mysql://localhost:3306/87a", "root", "root");
                   st=con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
           String sqlText = "SELECT image FROM image"; 
           ResultSet rset = st.executeQuery(sqlText); 
           while(rset.next()) {
                   Blob image = rset.getBlob("image"); 
                   img1= Image.getInstance(image.getBytes(1, (int) image.length()));
           }
           }catch (SQLException ex) 
           {
                   message = "ERROR: " + ex.getMessage();
                   ex.printStackTrace();
                   } 
                   finally {
                   if (con != null) {
                       //closes the database connection
                       try {
                           con.close();
                       } catch (SQLException ex) {
                           ex.printStackTrace();
                       }
                   }
                   }
         Image img = Image.getInstance(img1); 
         //img.scalePercent((document.right()-document.left())/((float)img.getWidth())*100);
          cb.addImage(img, 570, 0, 0, 60, gap, hei);
       }catch(IOException e){}
       catch(DocumentException e){}
       ColumnText.showTextAligned(cb, Element.ALIGN_MIDDLE, new Phrase(String.format(" Page %d of", writer.getPageNumber()),footerFont), document.right() - 60 , document.bottom() - 15, 0);
    }
    }
  
  OutputStream output=response.getOutputStream();
  response.setContentType("application/pdf");
  response.setHeader("Content-Disposition", "inline; filename=details.pdf");
  try{
          Document document = new Document(PageSize.A4, 20, 20, 70, 20);
  PdfWriter writer=PdfWriter.getInstance(document, output);
  document.open();
  BaseFont bf = BaseFont.createFont("c:/windows/fonts/arialuni.ttf", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
  writer.setPageEvent(new HeaderAndFooter(date));
  XMLWorkerHelper worker = XMLWorkerHelper.getInstance();
  List arrlist = new ArrayList();
  Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/gla", "root", "root");
  Statement st=con.createStatement( ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);  
  ResultSet rs=st.executeQuery("SELECT * FROM user_start2 where date='"+date+"' ");
   while(rs.next()){
   arrlist.add(rs.getString("data"));
   }
   document.add(new Paragraph(ds,new com.itextpdf.text.Font(bf, 12,Font.UNDERLINE)));
  for(int i=0;i&lt;4;i++){
    String str =(String) arrlist.get(i);
    document.add(new Paragraph(str,new com.itextpdf.text.Font(bf, 12)));
  }
  document.close();
  }catch(IOException e){e.printStackTrace();} 
  writer.flush();
  writer.close();
  output.close();
  %&gt;
  </code></pre>
  
  <p>Everything works, except that I dont get the total pages.</p>
  
  <p>What am I missing?</p>