【问题标题】:Printing JavaFX tableview with PrinterJob使用 PrinterJob 打印 JavaFX 表格视图
【发布时间】:2016-07-20 17:49:14
【问题描述】:

我想以横向格式将我的 tableView 打印到 A4 上。 我还希望 tableView 将自身扩展到此 A4 页面。

我设法做到了:

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

你可以清楚地看到我的桌子被切断了,右边的界限比左边的大很多。
有什么提示吗?

【问题讨论】:

    标签: javafx printing


    【解决方案1】:

    检查这个答案,这可能会有所帮助 hardware limitation issue

    来自 Javadocs:

    需要知道哪些边距值是合法的客户端应首先使用 HARDWARE_MINIMUM 边距获取 PageLayout。

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

    已编辑:我遇到了同样的问题,this Solution 对我很有效

    我得到的Result

    【讨论】:

      猜你喜欢
      • 2013-01-05
      • 1970-01-01
      • 1970-01-01
      • 2018-11-15
      • 1970-01-01
      • 1970-01-01
      • 2013-01-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多