I found a nice answer here about printing a non node object with JavaFX:
JavaFX printing non node objects
I'll report the code (I used exactly this):
PrinterJob job = PrinterJob.createPrinterJob();
PDFFile pdfFile = ... ;
if (job != null) {
boolean success = true ;
for (int pageNumber = 1; pageNumber <= pdfFile.getNumPages() ; pageNumber++) {
PDFPage page = pdfFile.getPage(pageNumber, true);
Rectangle2D bounds = page.getBBox();
int width = (int) bounds.getWidth();
int height = (int) bounds.getHeight();
java.awt.Image img = page.getImage(width, height, bounds, null, true, true);
BufferedImage bImg = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
bImg.createGraphics().drawImage(img, 0, 0, null);
javafx.scene.image.Image fxImg = SwingFXUtils.toFXImage(bImg, null);
ImageView imageView = new ImageView(fxImg);
success = success & job.printPage(imageView);
}
if (success) {
job.endJob();
}
}
My problem is now about the image quality. Premise that I don't need the best image quality, but what is needed is only a "readable" content. I tried to double width and height of the java.awt.Image and then rescale the bufferedImage but nothing happened.
Is possible to improve "just a little bit" the printed image? I found ghost4j but I don't want to make the project too heavy only because of this.
Thanks in advance