/** * Removes any attributes from the given AttributeSet that are * unsupported by the given PrintService/DocFlavor combination. */ @SuppressWarnings({ "unchecked", "rawtypes" }) private void removeUnsupportedAttributes(PrintService ps, DocFlavor flavor, AttributeSet aset) { AttributeSet asUnsupported = ps.getUnsupportedAttributes(flavor, aset); if (asUnsupported != null) { Attribute[] usAttrs = asUnsupported.toArray(); for (int i=0; i<usAttrs.length; i++) { Class category = usAttrs[i].getCategory(); if (ps.isAttributeCategorySupported(category)) { Attribute attr = (Attribute)ps.getDefaultAttributeValue(category); if (attr != null) { aset.add(attr); } else { aset.remove(category); } } else { aset.remove(category); } } } }
package org.kodejava.example.print; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.attribute.Attribute; import javax.print.attribute.AttributeSet; public class PrinterAttribute { public static void main(String[] args) { // // Locates the default print service for this environment. // PrintService printer = PrintServiceLookup.lookupDefaultPrintService(); if (printer != null) { // // Getting print service's attribute set. // AttributeSet attributes = printer.getAttributes(); for (Attribute a : attributes.toArray()) { String name = a.getName(); String value = attributes.get(a.getClass()).toString(); System.out.println(name + " : " + value); } } } }
set.add(new PrinterName(printQueueName, null)); javax.print.PrintService[] services = PrintServiceLookup.lookupPrintServices(null, set);
set.add(new PrinterName(printQueueName, null)); javax.print.PrintService[] services = PrintServiceLookup.lookupPrintServices(null, set);