The following code prints the node in portrait mode with US Letter pagesize rather than using the settings of the manually created pageLayout instance. The only way to get it to print in the wanted A4/Landscape layout is to select those settings manually in the Page Setup dialog.
try {
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
AnchorPane node = FXMLLoader.load(getClass().getResource("report.fxml"));
double scaleX = pageLayout.getPrintableWidth() / 1468.0;
double scaleY = pageLayout.getPrintableHeight() / 974.0;
node.getTransforms().add(new Scale(scaleX, scaleY));
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
job.showPageSetupDialog(null);
job.showPrintDialog(null);
boolean success = job.printPage(pageLayout, node);
if (success) {
job.endJob();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
try {
Printer printer = Printer.getDefaultPrinter();
PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
AnchorPane node = FXMLLoader.load(getClass().getResource("report.fxml"));
double scaleX = pageLayout.getPrintableWidth() / 1468.0;
double scaleY = pageLayout.getPrintableHeight() / 974.0;
node.getTransforms().add(new Scale(scaleX, scaleY));
PrinterJob job = PrinterJob.createPrinterJob(printer);
if (job != null) {
job.showPageSetupDialog(null);
job.showPrintDialog(null);
boolean success = job.printPage(pageLayout, node);
if (success) {
job.endJob();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}