How do I get print service attribute set?

This example demonstrates how to get print service’s attribute set using the javax.print API. First we find the default printer for the current machine using the PrintServiceLookup class. This will give us a PrintService object, this object might be null if no print service found.

The final step is to get the print service attribute set by calling getAttributes() method of the PrintService. We can convert the returned AttributeSet into an array using the toArray() method and iterates it.

An example result of this program is:

How do I get printer or print service name?

This example show you how to get the printer or print service installed on your machine. To get the installed services we can use PrinterJob.lookupPrintServices() method call. This method return an array of PrintService objects. After that call PrintService.getName() method to get the print service name.

The program will print the installed print service on your machine.

How do I get the default print service?

To look up the default print service we can use the javax.print.PrintServiceLookup class lookupDefaultPrintService() method.