@Override public void create(String filename) { // find the printing service //http://www.coderanch.com/t/385989/java/java/send-raw-data-printer AttributeSet attributeSet = new HashAttributeSet(); attributeSet.add(new PrinterName(filename, null)); PrintService[] services = PrintServiceLookup.lookupPrintServices(null, attributeSet); if(services.length > 0){ if(printFile != null){ printFile.deleteOnExit(); printFile = null; } try { printFile = File.createTempFile("printer_"+name,".redirect"); } catch (IOException e) { e.printStackTrace(); } printService = services[0]; } }
public AttributeSet getUnsupportedAttributes(final DocFlavor flavor, final AttributeSet attributes) { checkFlavor(flavor); if (attributes == null) { return null; } final AttributeSet result = new HashAttributeSet(); for (Attribute attr : attributes.toArray()) { if (!isAttributeValueSupported(attr, flavor, attributes)) { result.add(attr); } } return result.size() > 0 ? result : null; }
public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) { if (attributes == null) { return null; } if (flavor != null && !isDocFlavorSupported(flavor)) { throw new IllegalArgumentException("Flavor " + flavor.getMimeType() + " is not supported by print service"); } Attribute[] attrs = attributes.toArray(); HashAttributeSet unsupported = new HashAttributeSet(); for (int i = 0; i < attrs.length; i++) { if (!isAttributeValueSupported(attrs[i], flavor, attributes)) { unsupported.add(attrs[i]); } } if (unsupported.size() > 0) { return unsupported; } return null; }
public final void testMediaCategory() { HashAttributeSet aset = new HashAttributeSet(); MediaSizeName msn = MediaSizeName.ISO_A3; aset.add(msn); assertEquals(msn, aset.get(Media.class)); assertNull(aset.get(MediaSizeName.class)); MediaTray mt = MediaTray.BOTTOM; aset.add(mt); assertEquals(mt, aset.get(Media.class)); assertNull(aset.get(MediaTray.class)); MediaName mn = MediaName.ISO_A4_WHITE; aset.add(mn); assertEquals(mn, aset.get(Media.class)); assertNull(aset.get(MediaName.class)); }
public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) { if (flavor != null && !isDocFlavorSupported(flavor)) { throw new IllegalArgumentException("flavor " + flavor + "is not supported"); } if (attributes == null) { return null; } Attribute attr; AttributeSet unsupp = new HashAttributeSet(); Attribute[] attrs = attributes.toArray(); for (int i=0; i<attrs.length; i++) { try { attr = attrs[i]; if (!isAttributeCategorySupported(attr.getCategory())) { unsupp.add(attr); } else if (!isAttributeValueSupported(attr, flavor, attributes)) { unsupp.add(attr); } } catch (ClassCastException e) { } } if (unsupp.isEmpty()) { return null; } else { return unsupp; } }
public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) { if (flavor != null && !isDocFlavorSupported(flavor)) { throw new IllegalArgumentException("flavor " + flavor + "is not supported"); } if (attributes == null) { return null; } Attribute attr; AttributeSet unsupp = new HashAttributeSet(); Attribute []attrs = attributes.toArray(); for (int i=0; i<attrs.length; i++) { try { attr = attrs[i]; if (!isAttributeCategorySupported(attr.getCategory())) { unsupp.add(attr); } else if (!isAttributeValueSupported(attr, flavor, attributes)) { unsupp.add(attr); } } catch (ClassCastException e) { } } if (unsupp.isEmpty()) { return null; } else { return unsupp; } }
private static PrintService lookupByName(String name) { AttributeSet attributes = new HashAttributeSet(); attributes.add(new PrinterName(name, null)); for (PrintService service : PrintServiceLookup.lookupPrintServices(null, attributes)) { return service; } return null; }
public AttributeSet getUnsupportedAttributes(DocFlavor flavor, AttributeSet attributes) { if (flavor != null && !isDocFlavorSupported(flavor)) { throw new IllegalArgumentException("flavor " + flavor + " is not supported"); } if (attributes == null) { return null; } Attribute attr; AttributeSet unsupp = new HashAttributeSet(); Attribute []attrs = attributes.toArray(); for (int i=0; i<attrs.length; i++) { try { attr = attrs[i]; if (!isAttributeCategorySupported(attr.getCategory())) { unsupp.add(attr); } else if (!isAttributeValueSupported(attr, flavor, attributes)) { unsupp.add(attr); } } catch (ClassCastException e) { } } if (unsupp.isEmpty()) { return null; } else { return unsupp; } }