I want to print a PDFFile object from the Pdf-Renderer library using javafx printing. Is it possible to print non Node objects? Currently i'm using AWT printing (check this example) but it doesn't go well with javafx because my javafx window freezes when the AWT print dialog comes up.
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.DEFAULT);
PrinterJob job = PrinterJob.createPrinterJob();
if (job != null) {
boolean success = job.printPage(node); // use something otherthan a node(PDFFile in my case)
if (success) {
job.endJob();
}
}
You can get a
java.awt.Image
from each page, draw the page to ajava.awt.image.BufferedImage
convert theBufferedImage
to ajavafx.scene.image.Image
, and finally print anImageView
containing the image:Something like:
Note that this code can be executed off the FX Application Thread, to keep the UI responsive.