Friday, February 24, 2012

How To Get Installed Printer name using Java

1 comments
Get Installed printers in Java
  • You can get installed printers by using both javax.print.PrintService and javax.print.PrintServiceLookup 
  • PrintServiceLookup.lookupDefaultPrintService().getName(); will gives default printer name;

package jsupport.com;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;

/**
 *
 * @author Jsupport
 */

public class ShowPrinters {

    String defaultPrinter;
    public void SearchPrinter() {
        PrintService[] ser = PrintServiceLookup.lookupPrintServices(null, null);

        System.out.println("**************** All Printers ******************");
        for (int i = 0; i < ser.length; ++i) {
            String p_name = ser[i].getName();
            System.out.println(p_name);
        }
        System.out.println("***********************************************\n");
        defaultPrinter  =   PrintServiceLookup.lookupDefaultPrintService().getName();
        System.out.println("Default Printer  : "+defaultPrinter );
    }

    public static void main(String[] args) {
        new ShowPrinters().SearchPrinter();
    }
}


1 comments:

Javin Paul said...

Nice tip. Thanks for sharing information.

Javin
Quick tip to convert String to Enum in Java

Post a Comment