Java Printer Usage getPrintService(String printername)

Here you can find the source of getPrintService(String printername)

Description

get Print Service

License

Open Source License

Declaration

public static PrintService getPrintService(String printername) 

Method Source Code


//package com.java2s;
//    it under the terms of the GNU General Public License as published by

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

public class Main {
    public static PrintService getPrintService(String printername) {

        // Initalize print service

        if (printername == null) {
            return PrintServiceLookup.lookupDefaultPrintService();
        } else {/*from ww  w.ja  va 2s. com*/

            if ("(Show dialog)".equals(printername)) {
                return null; // null means "you have to show the print dialog"
            } else if ("(Default)".equals(printername)) {
                return PrintServiceLookup.lookupDefaultPrintService();
            } else {
                PrintService[] pservices = PrintServiceLookup
                        .lookupPrintServices(DocFlavor.SERVICE_FORMATTED.PRINTABLE, null);
                for (PrintService s : pservices) {
                    if (printername.equals(s.getName())) {
                        return s;
                    }
                }
                return PrintServiceLookup.lookupDefaultPrintService();
            }
        }
    }
}

Related

  1. getOrientationRequested(int value)
  2. getPaperTraysArray(PrintService ps)
  3. getPrinterAttributes(PrintService printer)
  4. getPrinterJobProperties(PrintService ps)
  5. getPrinterNames()
  6. getPrintServices()
  7. getResolution(PrintService service, PrintRequestAttributeSet set, boolean tryDefaultIfNull)
  8. getSetting(PrintService service, PrintRequestAttributeSet set, Class type, boolean tryDefaultIfNull)
  9. getSupportedAttributes(PrintService p)