Java Printer Usage getPrinterJobProperties(PrintService ps)

Here you can find the source of getPrinterJobProperties(PrintService ps)

Description

get Printer Job Properties

License

Open Source License

Declaration

@SuppressWarnings("unchecked")
public static Map<String, Object> getPrinterJobProperties(PrintService ps) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.HashMap;

import java.util.Map;

import javax.print.PrintService;
import javax.print.PrintServiceLookup;
import javax.print.attribute.Attribute;

public class Main {

    @SuppressWarnings("unchecked")
    public static Map<String, Object> getPrinterJobProperties(PrintService ps) {
        Map<String, Object> map = new HashMap<>();
        if (ps != null) {
            Class<? extends Attribute>[] supportedAttributes = (Class<? extends Attribute>[]) ps
                    .getSupportedAttributeCategories();
            for (int i = 0, max = supportedAttributes.length; i < max; i++) {
                Class<? extends Attribute> attr = supportedAttributes[i];
                map.put(supportedAttributes[i].getSimpleName(), ps.getDefaultAttributeValue(attr));
            }//from  w w w.j a v  a  2 s  . c  o  m
        }
        return map;
    }

    public static Map<String, Object> getPrinterJobProperties(String printerName) {
        PrintService ps = findPrintService(printerName);
        return getPrinterJobProperties(ps);
    }

    public static PrintService findPrintService(String printerName) {
        PrintService printService = null;
        if (printerName == null || printerName.isEmpty()) {
            printService = PrintServiceLookup.lookupDefaultPrintService();
        } else {
            PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
            for (PrintService service : services) {
                String prtName = service.getName();
                if (prtName.contains(printerName)) {
                    printService = service;
                    break;
                }
            }
        }
        return printService;
    }
}

Related

  1. getIntegerAttribute(String name, int value)
  2. getJobPriority(int pages, int copies, boolean withDialog)
  3. getOrientationRequested(int value)
  4. getPaperTraysArray(PrintService ps)
  5. getPrinterAttributes(PrintService printer)
  6. getPrinterNames()
  7. getPrintService(String printername)
  8. getPrintServices()
  9. getResolution(PrintService service, PrintRequestAttributeSet set, boolean tryDefaultIfNull)