In JavaFX, I want to print out a photo to 10x15 paper. There are some Paper constansts, but there is no 100x150 mm constant.
Is it possible to create an own Paper to use it in PageLayout?
Thanks.
PageLayout pageLayout = printer.createPageLayout(Paper.JAPANESE_POSTCARD, PageOrientation.LANDSCAPE, Printer.MarginType.EQUAL);
double scaleX = pageLayout.getPrintableWidth() / node.getBoundsInParent().getWidth();
double scaleY = pageLayout.getPrintableHeight() / node.getBoundsInParent().getHeight();
node.getTransforms().add(new Scale(scaleX, scaleY));
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
System.out.println("Job created!");
boolean success = job.printPage(node);
if (success) {
System.out.println("Job successfully finished!");
job.endJob();
} else {
System.out.println("Job NOT successful!");
}
}
You can use the class PrintHelper which has access to the package private constructor of Paper.
Paper photo = PrintHelper.createPaper("10x15", 100, 150, Units.MM);
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