Reputation: 20581
It is possible to get default system printer using Java Print Service API?
I can get list of all printers using
PrintServiceLookup.lookupPrintServices(null, null)
but how to get printer choosed as default in system? (In screen-shot below, the default printer is checked (HP Laser Jet)).
Upvotes: 5
Views: 18685
Reputation: 159774
You could use PrintServiceLookup.lookupDefaultPrintService
PrintService service =
PrintServiceLookup.lookupDefaultPrintService();
if (service != null) {
String printServiceName = service.getName();
System.out.println("Print Service Name is " + printServiceName);
} else {
System.out.println("No default print service found");
}
Upvotes: 3
Reputation: 68962
PrintService service =
PrintServiceLookup.lookupDefaultPrintService();
Upvotes: 2
Reputation: 13872
You should use PrintServiceLookup
import javax.print.PrintServiceLookup;
PrintService service = PrintServiceLookup.lookupDefaultPrintService();
Acc. to Javadocs:
lookupDefaultPrintService Locates the default print service for this environment. This may return null. If multiple lookup services each specify a default, the chosen service is not precisely defined, but a platform native service, rather than an installed service, is usually returned as the default. If there is no clearly identifiable platform native default print service, the default is the first to be located in an implementation-dependent manner.
Upvotes: 14