List of utility methods to do Printer Usage
Attribute | getEnumAttribute(String name, Object value) Instantiates an EnumSyntax based attribute with the given IPP name and the given value (Enums maybe int or String based).
Class<?> attrClass = getClass(name); if (attrClass == null) return null; try { Field[] fields = attrClass.getDeclaredFields(); for (int i = 0; i < fields.length; i++) { Field field = fields[i]; if (field.getType().equals(attrClass)) { ... |
Attribute | getIntegerAttribute(String name, int value) Instantiates an IntegerSyntax based attribute with the given IPP name for the given int value.
Class<?> attrClass = getClass(name); if (attrClass == null) return null; try { INTEGER_ATT_VALUE[0] = Integer.valueOf(value); Constructor<?> c = attrClass.getDeclaredConstructor(INTEGER_CLASS_ARRAY); return (Attribute) c.newInstance(INTEGER_ATT_VALUE); } catch (SecurityException e) { ... |
JobPriority | getJobPriority(int pages, int copies, boolean withDialog) Get Job Priority based on pages printed. int priority = copies * pages; if (withDialog) priority *= 2; priority = 100 - priority; if (priority < 10) priority = 10; else if (priority > 100) priority = 100; ... |
OrientationRequested | getOrientationRequested(int value) get Orientation Requested if (OrientationRequested.LANDSCAPE.getValue() == value) return OrientationRequested.LANDSCAPE; if (OrientationRequested.PORTRAIT.getValue() == value) return OrientationRequested.PORTRAIT; if (OrientationRequested.REVERSE_LANDSCAPE.getValue() == value) return OrientationRequested.REVERSE_LANDSCAPE; if (OrientationRequested.REVERSE_PORTRAIT.getValue() == value) return OrientationRequested.REVERSE_PORTRAIT; ... |
Media[] | getPaperTraysArray(PrintService ps) get Paper Trays Array List<Media> list = getPaperTrays(ps); return Arrays.copyOf(list.toArray(), list.size(), Media[].class); |
Set | getPrinterAttributes(PrintService printer) get Printer Attributes Set<Attribute> set = new LinkedHashSet<>(); Class<? extends Attribute>[] categories = (Class<? extends Attribute>[]) printer .getSupportedAttributeCategories(); DocFlavor[] flavors = printer.getSupportedDocFlavors(); AttributeSet attributes = printer.getAttributes(); for (Class<? extends Attribute> category : categories) { for (DocFlavor flavor : flavors) { Object value = printer.getSupportedAttributeValues(category, flavor, attributes); ... |
Map | getPrinterJobProperties(PrintService ps) get Printer Job Properties 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)); return map; |
String[] | getPrinterNames() get Printer Names String[] result = new String[printServices.length]; for (int i = 0; i < printServices.length; i++) result[i] = printServices[i].getName(); return result; |
PrintService | getPrintService(String printername) get Print Service if (printername == null) { return PrintServiceLookup.lookupDefaultPrintService(); } else { if ("(Show dialog)".equals(printername)) { return null; } else if ("(Default)".equals(printername)) { return PrintServiceLookup.lookupDefaultPrintService(); } else { ... |
PrintService[] | getPrintServices() Get Print Services for standard flavor and pratt return PrintServiceLookup.lookupPrintServices(getDefaultFlavor(), getDefaultPrintRequestAttributes());
|