使用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.