1
我有一個java打印程序,但由於某種原因,它總是選擇默認打印機(8600),即使當我通過打印機的xps值時,我做錯了,我怎樣才能得到它來選擇所需的打印機總是選擇默認的打印機,而不是指定的打印機,JAVA
繼承人我的代碼:
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
謝謝