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.

package org.kodejava.example.print;

import javax.print.PrintService;
import java.awt.print.PrinterJob;

public class PrintName {
    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 = Send To OneNote 2007
Name = Microsoft XPS Document Writer
Name = HP LaserJet P1005
Name = Epson LX-300+
Name = EPSON LQ-300+ ESC/P 2
Name = CutePDF Writer

Wayan Saryada

Programmer, runner, recreational diver, currently living in the island of Bali, Indonesia. Mostly programming in Java, creating web based application with Spring Framework, Hibernate / JPA.

Leave a Reply