title: JavaFX convert WritableImage to Image
body: <p>I am doing some application which makes a screenshot of <code>LineChart</code> and save it to <strong>pdf</strong> file. So I don't know a smooth way to convert <code>WritableImage</code> (JavaFX 2.2) to <code>Image</code> (iText lib).</p>
  <p>My temporary solution is:</p>
  <ol>
  <li>to make a snapshot, then</li>
  <li>get the <code>WritableImage</code> from the snapshot</li>
  <li>write the image to a png file</li>
  <li>open the image and make iText object <code>Image</code></li>
  </ol>
  <p>I would like to make some changes: I don't want to write the <code>png</code> file to disc, I just want the snapshot to be written to a pdf file.</p>
  <p>My temporary solution is:</p>
  <pre><code> WritableImage wim = new WritableImage((int) lineChart.getWidth(),(int) lineChart.getHeight());
   Scene scena = primaryStage.getScene();
   scena.snapshot(wim);
   
   File fileA = new File(&quot;C://Graphs/chart.png&quot;);
   try {
        ImageIO.write(SwingFXUtils.fromFXImage(wim, null), &quot;png&quot;, fileA);
   }
   catch (Exception s) {
   }
   pdfDocument.add(preface3);
   com.itextpdf.text.Image graph =com.itextpdf.text.Image.getInstance(&quot;C://Graphs/chart.png&quot;);
   pdfDocument.add((com.itextpdf.text.Element) graph);        
  </code></pre>