Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaFX print custom paper size

Tags:

javafx

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!");
        }
    }
like image 485
Xdg Avatar asked Nov 20 '25 16:11

Xdg


1 Answers

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);
like image 164
mikevinmike Avatar answered Nov 23 '25 07:11

mikevinmike



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!