2016-04-21 69 views
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?

回答

0

检查这个答案,这可能有助于 hardware limitation issue

从的Javadoc:

,需要知道什么是空白的值是法律应该首先获得使用HARDWARE_MINIMUM利润率页面布局客户端。

如果为指定的打印机不能支持布局,它会通过调整返回布局支持的配置

编辑:我有同样的问题,this Solution 为我工作的伟大

Result我有 。