title: Add image above table - Itext
body: <p>How to add an image over a table with Itext?</p>
  
  <p><strong>I'm using the version 5.5.10</strong></p>
  
  <p><strong>implementation 'com.itextpdf:itextg:5.5.10'</strong></p>
  
  <p><strong>Edit: The image can not be inside the row / column, it must be independent to populate any position on the screen</strong></p>
  
  <p>I'm trying to add an image over the columns of a table, but the result is this:</p>
  
  <p><a href="https://i.stack.imgur.com/jwosR.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jwosR.jpg" alt="enter image description here"></a></p>
  
  <p>It always lies below the rows of the column.
  To add the image I'm doing so:</p>
  
  <pre><code>public void addImg (int dwb, float x, float y, float desc) {
      try{
          Bitmap bitmap = dwbToBitmap(context, dwb);
          ByteArrayOutputStream stream3 = new ByteArrayOutputStream();
          bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream3);
  
          Image image = Image.getInstance(stream3.toByteArray());
          stream3.close();
          image.scaleToFit(sizeImgFit, sizeImgFit);
          image.setAbsolutePosition(35.6f + 10f + x, height-y-sizeImg-(height-desc));
  
          document.add(image);
  
      }catch (Exception e){
          log("addImg", e);
      }
  }
  </code></pre>
  
  <p>I have already tried to change the order, create the first table and then add the images or vise versa, but it does not work.</p>
  
  <p>Does anyone know how to put the images in position Z above all?</p>
  
  <p>I create the table like this:</p>
  
  <pre><code>public void createTable(ArrayList&lt;String&gt; header, ArrayList&lt;String[]&gt; clients){
      float height = 569/header.size();
      sizeImg = height;
      sizeImgFit = sizeImg - 2;
      PdfPTable pdfPTable = new PdfPTable(header.size());
      pdfPTable.setWidthPercentage(100);
  
      PdfPCell pdfPCell;
  
      int indexC = 0;
  
      while(indexC &lt; header.size()){
          pdfPCell = new PdfPCell(new Phrase(header.get(indexC++), fHeaderText));
          pdfPCell.setHorizontalAlignment(Element.ALIGN_CENTER);
          pdfPCell.setBackgroundColor(BaseColor.GRAY);
          pdfPTable.addCell(pdfPCell);
  
      }
  
      int i = 0;
      for(String[] row : clients){
          int p = 0;
          for(String linha : row){
              pdfPCell = new PdfPCell(new Phrase(linha, fText));
              pdfPCell.setHorizontalAlignment(Element.ALIGN_CENTER);
              pdfPCell.setVerticalAlignment(Element.ALIGN_CENTER);
              pdfPCell.setFixedHeight(height);
  
              pdfPTable.addCell(pdfPCell);
              log("linha - coluna", i + " - " + p);
              p++;
          }
          i++;
      }
  
      //paragraph.add(pdfPTable);
  
      try {
          document.add(pdfPTable);
  
      }catch (Exception e){
          log("paragraph", e);
      }
  }
  </code></pre>
  
  <p>These methods mentioned above are in a class:</p>
  
  <pre><code>public class TemplatePDF {
      private Context context;
      private File pdfFile;
      private Document document;
      public PdfWriter pdfWriter;
      private Paragraph paragraph;
      private Rotate event;
      private Font fTitle = new Font(Font.FontFamily.TIMES_ROMAN, 20, Font.BOLD);
      private Font fSubTitle = new Font(Font.FontFamily.TIMES_ROMAN, 18, Font.BOLD);
      private Font fHeaderText = new Font(Font.FontFamily.TIMES_ROMAN, 3, Font.NORMAL, BaseColor.WHITE);
      private Font fText = new Font(Font.FontFamily.TIMES_ROMAN, 3);
      private Font fHText = new Font(Font.FontFamily.TIMES_ROMAN, 8);
      private Font fHighText = new Font(Font.FontFamily.TIMES_ROMAN, 15, Font.BOLD, BaseColor.RED);
      private float width = PageSize.A4.getWidth();
      private float height = PageSize.A4.getHeight();
      public float sizeImg;
      public float sizeImgFit;
  
      public TemplatePDF(Context context){
          this.context = context;
      }
  
      public void openDocument(){
          createFile();
  
          try{
              document = new Document(PageSize.A4);
              pdfWriter = PdfWriter.getInstance(document, new FileOutputStream(pdfFile));
              event = new Rotate();
              document.open();
  
          }catch (Exception e){
              Log.e("erro", e.toString());
          }
      }
  
      private void createFile(){
          File folder = new File(Environment.getExternalStorageDirectory().toString(), "PDF");
  
          if(!folder.exists()){
              folder.mkdirs();
          }
  
          pdfFile = new File(folder,  key() + ".pdf");
      }
  
      public void closeDocument(){
          document.close();
      }
  
      ...
  
  }
  </code></pre>
  
  <p>To create PDF, I do so:</p>
  
  <pre><code>        //Creating the object
          TemplatePDF templatePDF = new TemplatePDF(ficha_pre.this);
          templatePDF.openDocument();
          templatePDF.addMetaData("Relatório", "Situs", "Woton Sampaio");
          templatePDF.addTitles("Relatório", "","Data: " + getDate());
  
          //Creating the table
          ArrayList&lt;String&gt; header = new ArrayList&lt;&gt;();
          for(int i = 0; i &lt; 55; i++){
              header.add(forString(i));
          }
  
          ArrayList&lt;pdfItens&gt; itens = arrayItens();
          ArrayList&lt;String[]&gt; files = array();
  
          templatePDF.createHeaderFicha(itens);
          templatePDF.createTable(header, files);
  
          //Adding image
          templatePDF.addImg(R.drawable.ic_a, 0, 20, 566);
  </code></pre>