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:
WritableImage
from the snapshotImage
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);
Use:
ByteArrayOutputStream byteOutput = new ByteArrayOutputStream();
ImageIO.write( SwingFXUtils.fromFXImage( wim, null ), "png", byteOutput );
com.itextpdf.text.Image graph;
graph = com.itextpdf.text.Image.getInstance( byteOutput.toByteArray() );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With