title: Place an image on a PDF file using JavaFX
body: <p>I've manged  to place text into a pdf file using Javafx and PDFbox from Apache. Now I am trying to place an image from taking a screen shot of a scene, to the pdf document. </p>
  
  <pre><code>    WritableImage snapshot = quotes.getScene().snapshot(null);
      PDDocument doc = null;
      PDPage page = null;
      PDXObjectImage ximg = null;
      BufferedImage bufferedImg = SwingFXUtils.fromFXImage(snapshot, null);
  
     try{
         doc = new PDDocument();
         page = new PDPage();
  
  
         doc.addPage(page);
         PDPageContentStream content = new PDPageContentStream(doc, page);
  
  
        /* ByteArrayOutputStream out = new ByteArrayOutputStream();
        InputStream in = new ByteArrayInputStream(out.toByteArray());*/
  
        ximg = new PDJpeg(doc, bufferedImg);
        //ximg = new PDJpeg(doc, in);
        content.drawImage(ximg, 100, 100);
  
        content.close();
        doc.save("PDFWithText.pdf");
        doc.close();
      } catch (Exception e){
      System.out.println(e);
      }
  </code></pre>
  
  <p>When I use the InputStream and OutputStream classes, the document is created but when I open it, Adobe along with other programs gives me an error saying Acrobat cannot display page correctly. When I use the BufferedImage class instead that is commented out in the above code, the document is simple not created and I don't know why.</p>
  
  <p><em>NOTE</em></p>
  
  <p>This is a follow-up question to <a href="https://stackoverflow.com/questions/18024498/taking-a-screenshot-of-a-scene-or-a-portion-of-a-scene-in-javafx-2-2/">Taking a screenshot of a scene or a portion of a scene in JavaFx 2.2</a>, but specific to the pdf creation portion rather than the node snapshot portion.</p>