title: PdfBox adding multiple images into pdf
body: <p>I try to add multiple images into a pdf with pdfbox 2.0.8, but currently only one will be added. I have two different images which should be attached to two different acrofields, but only the last one of my list will be added. </p>
  
  <p>This is my test function:</p>
  
  <pre><code>@Test
  public void attachBulkImageToField(){
  
      List&lt;ImageData&gt; data = new ArrayList&lt;&gt;();
  
      data.add(new ImageData(signatureAusstellerField,signatureAussteller.toPath()));
      data.add(new ImageData(signatureDienstleisterField, signatureDienstleister.toPath()));
  
      ImageToFieldDrawer imgDrawer = new ImageToFieldDrawer(pdf);
      assertTrue(imgDrawer.drawImageToField(data, Paths.get("d:\\imageBulk.pdf")));
  
  }
  
  
  public boolean drawImageToField(List&lt;ImageData&gt; data, final Path outPath) {
      try {
          for (ImageData element : data) {
              addImageForField(element.getImagePath(), getAcroFieldWithName(element.getFieldName()));
          }
          savePdf(outPath);
          return true;
  
      } catch (IOException e) {
          e.printStackTrace();
      } catch (PDFSizeException e) {
          e.printStackTrace();
      }
      return false;
  }
  
  
  private void savePdf(Path outPath) throws IOException {
      pdDocument.save(outPath.toFile());
      pdDocument.close();
  }
  
  private void addImageForField(Path signature, AcroField targetField) throws IOException {
      PDPage page = pdDocument.getPage(targetField.getPageNr() - 1);
      DrawImage image = new DrawImage(Files.readAllBytes(signature), 0, 0);
      PDImageXObject pdImage = PDImageXObject.createFromFile(signature.toAbsolutePath().toString(), pdDocument);
  
      try(PDPageContentStream contentStream = new PDPageContentStream(pdDocument, page)){
          contentStream.drawImage(pdImage, targetField.getX(), targetField.getY(), targetField.getWidth(), targetField.getHeight());
      }
  }
  
  
  
  public class ImageData {
  
  private String fieldName;
  private Path imagePath;
  
  public ImageData(String fieldName, Path imagePath) {
      this.fieldName = fieldName;
      this.imagePath = imagePath;
  }
  
  public String getFieldName() {
      return fieldName;
  }
  
  public void setFieldName(String fieldName) {
      this.fieldName = fieldName;
  }
  
  public Path getImagePath() {
      return imagePath;
  }
  
  public void setImagePath(Path imagePath) {
      this.imagePath = imagePath;
  }
  </code></pre>
  
  <p>}</p>