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.
package org.kodejava.print;
import javax.print.PrintService;
import java.awt.print.PrinterJob;
public class PrinterName {
public static void main(String[] args) {
// Lookup for the available print services.
PrintService[] printServices = PrinterJob.lookupPrintServices();
// Iterates the print services and print out its name.
for (PrintService printService : printServices) {
String name = printService.getName();
System.out.println("Name = " + name);
}
}
}
The program will print the installed print service on your machine.
Name = OneNote for Windows 10
Name = OneNote (Desktop)
Name = Microsoft XPS Document Writer
Name = Microsoft Print to PDF
Name = HP LaserJet P1005
Name = Fax
Latest posts by Wayan (see all)
- How do I use Proxy class to configure HTTP and SOCKS proxies in Java? - March 27, 2025
- How do I retrieve network interface information using NetworkInterface in Java? - March 26, 2025
- How do I work with InetAddress to resolve IP addresses in Java? - March 25, 2025
PrinterJob.lookupPrintServices()
will print the server printer names (name of printers where application is deployed) not client machine printer name.