Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用java.awt.Desktop打开打印对话框_Java_Printing_Awt - Fatal编程技术网

使用java.awt.Desktop打开打印对话框

使用java.awt.Desktop打开打印对话框,java,printing,awt,Java,Printing,Awt,我试图使用java.awt.Desktop.print打印HTML文件,但是打印对话框抛出了一个IOException menuPrint.setOnAction((ActionEvent t) -> { if (Desktop.isDesktopSupported()) { Desktop desktop = Desktop.getDesktop(); if (desktop.isSupported(Desktop.Action.PRINT))

我试图使用
java.awt.Desktop.print
打印HTML文件,但是打印对话框抛出了一个
IOException

menuPrint.setOnAction((ActionEvent t) -> {
     if (Desktop.isDesktopSupported()) {
        Desktop desktop = Desktop.getDesktop();
        if (desktop.isSupported(Desktop.Action.PRINT)) {
            try {
                File output = new File(System.getProperty("java.io.tmpdir")+"/Preview.html");
                desktop.print(output);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
});

我安装了一台PDF打印机,可以使用Ctrl+p打开打印对话框。虽然相同的代码在连接到实际打印机的单独机器上工作


任何线索都很感激。如何使其工作?

我从未尝试过使用桌面打印。我一直使用java .AWT.Prime.PrTrPopWork.@ Gilbert Le Blanc,你有任何示例代码吗?甲骨文教程。@Sudip Saha:我也遇到了同样的问题。找到解决办法了吗?@PieterDegraeuwe不幸没有。虽然我通过允许用户从浏览器控件本身打印而绕过了这个问题,但我从未尝试过用桌面打印。我一直使用java .AWT.Prime.PrTrPopWork.@ Gilbert Le Blanc,你有任何示例代码吗?甲骨文教程。@Sudip Saha:我也遇到了同样的问题。找到解决办法了吗?@PieterDegraeuwe不幸没有。虽然我通过允许用户从浏览器控件本身获取打印输出绕过了这一点。
java.io.IOException: Failed to print C:\Users\XXX\AppData\Local\Temp\Preview.html. 
    Error message: A device attached to the system is not functioning.