gpt4 book ai didi

java - 总是选择默认打印机而不是指定的打印机,JAVA

转载 作者:太空宇宙 更新时间:2023-11-04 07:45:57 26 4
gpt4 key购买 nike

我有一个java打印程序,但由于某种原因它总是选择默认打印机(8600),即使我为打印机传递一个xps值,我做错了什么,以及如何让它选择所需的打印机

这是我的代码:

 PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
System.out.println("Number of print services: " + printServices.length); //tells me how many print services are isntalled on the server.

for (PrintService printer2 : printServices) {
System.out.println("Printer: " + printer2.getName()); //prints out the names of all printers on the server, testing purposes
}


PrintUtility.findPrintService(printer); // selects only the 8600 printer // EDIT now selects any printer with the name provided


PrintService[] services =
PrintServiceLookup.lookupPrintServices(psInFormat, null);
//System.out.println("Printers avialiable are " + services);
System.out.println("Printer Selected " + services[Printerinx]);

//PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();

DocFlavor[] docFalvor = services[Printerinx].getSupportedDocFlavors();
for (int i = 0; i < docFalvor.length; i++) {
System.out.println(docFalvor[i].getMimeType());
}
if (services.length > 0) {
DocPrintJob job = services[Printerinx].createPrintJob();
try {
job.print(myDoc, aset);
System.out.print("Printing Doc");
} catch (PrintException pe) {
System.out.print(pe);
}
}

这是控制台:

INFO: Number of print services: 7
INFO: Printer: Send To OneNote 2013
INFO: Printer: Microsoft XPS Document Writer
INFO: Printer: HP988FD1 (HP Officejet Pro 8600)
INFO: Printer: HP Officejet Pro 8600 (Network)
INFO: Printer: Fax - HP Officejet Pro 8600 (Network)
INFO: Printer: Fax
INFO: Printer: Adobe PDF
INFO: Printer Selected Win32 Printer : HP Officejet Pro 8600 (Network)
INFO: image/gif

谢谢

最佳答案

好的解决了,printerinx,我已经选择了可以使用哪台打印机,第一个打印机为 0,等等,我已将其设置为 printinx =“3”,因此它总是选择第四个打印机,这已被删除,并且每个打印机都给出了正确的 printinx,现在它应该正常工作

关于java - 总是选择默认打印机而不是指定的打印机,JAVA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15274716/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com