我想在新页面上打印许多SpliPanes,每个SplitPane。

时间:2015-04-23 16:06:01

标签: printing javafx

我有一个包含许多SplitPanes的ArrayList。 每个SplitPane我都想打印到新页面。 它不起作用。

@FXML
private void handlePrint(ActionEvent event) {
    for (Object split : listSplitPanes) {
        printModul.print((Node) split);
    }


public void print(final Node node) {
    Printer printer = Printer.getDefaultPrinter();
    PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, Printer.MarginType.DEFAULT);
    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();
    if (job != null) {
        if (job.showPrintDialog(primaryStage.getOwner())) {
            boolean success = job.printPage(pageLayout, node);
            if (success) {
                job.endJob();
            }
        }
    }
}

没有错误。它打印出第一个完美的SplitPane,每个都有空页。

有人有想法吗?

谢谢 格哈德·莱布

1 个答案:

答案 0 :(得分:-1)

@Gerhard Laib 您的工作已完成且布尔成功为真,因此打印job.endJob结束 我会尝试编写一些测试来打印保持打印作业活动的其他节点。抱歉没有代码,因为我正在尝试使用GridPane打印多个页面而没有太多运气。谁曾为JavaFX编写教程我猜想从未想过打印和桌面应用程序