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

时间:2015-07-07 12:06:43

标签: 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)) {
            try {
                File output = new File(System.getProperty("java.io.tmpdir")+"/Preview.html");
                desktop.print(output);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
});
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.

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

任何线索都表示赞赏。如何使它工作?

0 个答案:

没有答案
相关问题