我正在使用java打印一些东西,我注意到我的Systemwide Defaultprinter更改为我上次使用的打印机。这是为什么? 我的程序不应该这样做。任何想法?
String printerNameDesired = "Adobe PDF";
PrintService[] service = PrinterJob.lookupPrintServices(); // list of printers
DocPrintJob docPrintJob = null;
int count = service.length;
for (int i = 0; i < count; i++)
{
if (service[i].getName().equalsIgnoreCase(printerNameDesired))
{
docPrintJob = service[i].createPrintJob();
i = count;
}
}
PrinterJob job = PrinterJob.getPrinterJob();
try
{
job.setPrintService(docPrintJob.getPrintService());
}
catch (PrinterException ex)
{
Logger.getLogger(HelloWorldPrinter.class.getName()).log(Level.SEVERE, null, ex);
}
PageFormat pf = job.defaultPage();
Paper paper = new Paper();
int margin = 0;
paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2);
pf.setPaper(paper);
job.setPrintable(this, pf);
//boolean ok = job.printDialog(); //ruft den auswahl-dialog auf
try
{
job.print();
}
catch (PrinterException ex)
{
Logger.getLogger(HelloWorldPrinter.class.getName()).log(Level.SEVERE, null, ex);
}
最近在“job.print();”使用的打印机服务在Windows“设备和打印机”中设置为默认打印机。 Tnaks任何帮助
答案 0 :(得分:-2)
这不是Java错误,而是Win 10功能,可以通过以下方式关闭:
Start(Window)Icon/Settings/Devices/Printers & scanners/Let Windows manage my
default printer: Off
或者,在德国的Windows上:
Start(Window)Icon/Einstellungen/Geräte/Drucker & Scanner/Standarddrucker von
Windows verwalten lassen: Aus