我遇到java.awt.print.PrinterException:打印机不接受作业..发送文档进行动态打印时,我的jsp页面中出现异常......
String pdfFile = "D://Records.pdf";
boolean silentPrint = false;
String printerindx = "1";
String password = "";
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
if (pdfFile == null) {
System.out.println("No PDF file available");
}
PDDocument document = null;
try {
document = PDDocument.load(pdfFile);
if (document.isEncrypted()) {
document.decrypt(password);
}
PrinterJob printJob = PrinterJob.getPrinterJob();
if (printerindx != null) {
PrintService[] printServices = PrinterJob.lookupPrintServices();
for (PrintService printService : printServices) {
if (printService.getName().equals("HP LaserJet P1007") {
System.out.println("Printer found ....");
printJob.setPrintService(printService);
System.out.println(printService);
}
}
}
document.print(printJob);
} finally {
if (document != null) {
document.close();
}
}
System.out.println("Printing Completed...");
出了什么问题?
最佳答案
据此:openjdk bug这是打印库中的错误,您有一些选择:
- 使用不同的 JRE 来修复错误。
- 重复打印,直到不再抛出为止,有类似问题的人说它通常在第一次重复时有效。
- 从这里使用黑客:hack ,参见ForcedAcceptPrintService类
关于java.awt.print.PrinterException : Printer is not accepting job,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17694722/