小编Kac*_*Sys的帖子

JavaFX8 Print API:如何正确设置Printable区域

在我的javafx应用程序中,我使用JavaFX 8打印API来打印节点,我遇到了打印区域的问题,尽管我已经用A4纸设置了pageLayout ....这是我的代码:

public static  void printNode(final Node node) throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Printer printer = Printer.getDefaultPrinter();   
        PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.PORTRAIT, 0,0,0,0 );      
        PrinterJob job = PrinterJob.createPrinterJob();
        if (job != null  && job.showPrintDialog(node.getScene().getWindow()) ) { 
            boolean success = job.printPage(pageLayout, node);                   
            if (success) {
                job.endJob();
            }
        }
Run Code Online (Sandbox Code Playgroud)

以下是我要打印的节点的快照: 在此输入图像描述

这是我打印节点时得到的内容 在此输入图像描述

printing javafx

6
推荐指数
1
解决办法
5668
查看次数

标签 统计

javafx ×1

printing ×1