I found some basic example how to print web page with JavaFX but I'm looking for examplewhich can print the complete Scene with app content. Is there any example?
Asked
Active
Viewed 3,131 times
1
-
Look at this [answer](http://stackoverflow.com/questions/22789449/export-stage-into-pdf/22796964#22796964) – xuesheng Apr 01 '14 at 21:12
1 Answers
3
You can convert your scene to an image using
WritableImage snapshot = scene.snapshot(null);
This will return a WritableImage, which can be converted to an Image File or BufferedImage, and print using the Printing API of JavaFX8 (there are not lot of examples available for this, but the new API has quite a resemblance to the old Printing API, so it won't be a problem)
Converting WritableImage to Png File
WritableImage snapshot = scene.snapshot(null);
File file = new File("image.png");
try {
ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", file);
} catch (IOException e) {
e.printStackTrace();
}
Converting WritableImage to BufferedImage (used for printing)
WritableImage snapshot = scene.snapshot(null);
BufferedImage bufferedImage = SwingFXUtils.fromFXImage(snapshot, null);
For just a small example of how to print an Image using java, please go through

Community
- 1
- 1

ItachiUchiha
- 36,135
- 10
- 122
- 176