java.awt.print.PrinterException:打印机不接受作业
我面临java.awt.print.PrinterException:打印机不接受作业..发送文档进行动态打印时jsp页面出现异常java.awt.print.PrinterException:打印机不接受作业,java,jsp,servlets,Java,Jsp,Servlets,我面临java.awt.print.PrinterException:打印机不接受作业..发送文档进行动态打印时jsp页面出现异常 String pdfFile = "D://Records.pdf"; boolean silentPrint = false; String printerindx = "1"; String password = ""; PrintService default
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...");
出了什么问题?根据这一点:打印库时出错,您可以选择:
什么失败了 我之前曾尝试过皮罗第三条建议的解决方案,但我收到了与后续海报(post#10)相同的错误 什么有效 我执行了,它覆盖了Win32PrintService getPrinterIsAcceptingJobs()方法,以始终返回“ACCEPTING_JOBS”状态。这非常适合我的需要:打印机始终被视为可用,即使它实际上处于脱机状态,只要它再次联机,打印作业都会排队等待。我唯一需要做的不同的事情就是从GitHub获取一个旧版本的(3.18),因为我是用Java7编译的。尝试使用最新版本(3.20)编译(使用Java 8构建)时出现以下错误: java.lang.UnsupportedClassVersionError:sun/print/Win32PrintService:不支持的主版本。次版本52.0 对于不熟悉创建PrintServiceFixer.jar所需编译的其他人,以下是我采取的步骤:
java -cp .;.\ext\javassist.jar Win32PrintServiceFixer
java -jar -Xbootclasspath/p:path\to\my\program's\libs\PrintServiceFixer.jar MyPrintingProgram.jar
很可能打印机不接受这份工作。。。除此之外,很难知道该说些什么。运行JSP的用户(当然是在服务器端)可能没有访问打印机的权限。。。
java -jar -Xbootclasspath/p:path\to\my\program's\libs\PrintServiceFixer.jar MyPrintingProgram.jar