0
我想以横向格式将我的tableView打印到A4上。 我也希望tableView缩放到这个A4页面。使用PrinterJob打印JavaFX tableview
我成功地做到这一点:
Printer printer = Printer.getDefaultPrinter();
PrinterJob printerJob = PrinterJob.createPrinterJob();
//set layout to A4 and landscape
PageLayout pageLayout = printer.createPageLayout(Paper.A4,
PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT);
printerJob.getJobSettings().setPageLayout(pageLayout);
System.out.println(pageLayout.getPrintableWidth());
System.out.println(pageLayout.getPrintableHeight());
final double scaleX = pageLayout.getPrintableWidth()/_menuPlanTable.getBoundsInParent().getWidth();
final double scaleY = pageLayout.getPrintableHeight()/_menuPlanTable.getBoundsInParent().getHeight();
_menuPlanTable.getTransforms().add(new Scale(scaleX, scaleY));
if(printerJob.showPrintDialog(_controlStage) && printerJob.printPage(_menuPlanTable)) {
_menuPlanTable.getTransforms().remove(getTransforms().size());
printerJob.endJob();
}
else{
_menuPlanTable.getTransforms().remove(getTransforms().size());
}
结果看起来是这样的: IMAGE
你可以清楚地看到,我的表被切断和约束的权利是很多比左边大。
任何tipps?