title: Adding image layers to a pdf using iText 5 or 7
body: <p>I need to create a pdf document with images that should be contained in layers. Each image should be contained in a layer, so that we can choose to make each image either visible or not. </p>
  
  <p>I know that iText offers a class <strong><em>PdfLayer</em></strong> for that purpose but they don't explain how to use it. Surprisingly tutorials in the web don't cover this question.</p>
  
  <p>This is a little start:</p>
  
  <pre><code>    // Creating a PdfWriter 
      String dest = "export.pdf"; 
      PdfWriter writer = new PdfWriter(dest);
  
      // Creating a PdfDocument  
      PdfDocument pdfDoc = new PdfDocument(writer);
  
  
      // Adding an empty page 
      //pdfDoc.addNewPage(); 
  
      // Creating a Document   
      Document document = new Document(pdfDoc); 
  
      /////////////////////////////////////////////////////////
  
      // Creating an ImageData object 
      String imageFile = "map.png"; 
      ImageData data = ImageDataFactory.create(imageFile);
  
      // Creating an Image object 
      Image img = new Image(data);
  
      PdfLayer pdflayer = new PdfLayer("main layer", pdfDoc);
      pdflayer.setOn(true); 
  
      /* normally, here where the image should be added to the layer */
  </code></pre>
  
  <p>Hope for your help, thanks!</p>