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