import javax.print.*; class Test { public static void main (String [] args) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Number of print services: " + printServices.length); for (PrintService printer : printServices) System.out.println("Printer: " + printer.getName()); } }
/** * List available devices * @return returns a list of available devices that accepts DocFlavor.INPUT_STREAM.AUTOSENSE */ public static PrintService[] getDevices() { PrintService[] printers = PrintServiceLookup.lookupPrintServices(FLAVOR, null); return printers; }
/** * List available devices * @return returns a list of available devices that accepts DocFlavor.INPUT_STREAM.AUTOSENSE */ public static PrintService[] getDevices() { PrintService[] printers = PrintServiceLookup.lookupPrintServices(FLAVOR, null); return printers; }
import javax.print.*; class Test { public static void main (String [] args) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Number of print services: " + printServices.length); for (PrintService printer : printServices) System.out.println("Printer: " + printer.getName()); }
import javax.print.PrintService; import javax.print.PrintServiceLookup; public class CheckInstalledPrinter { public static void main (String [] args) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Total Services :: " + printServices.length); for (PrintService printer : printServices) System.out.println("Printer Name :: " + printer.getName()); } }
private PrintService[] lookForPrintServices() { PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PRINTABLE, null); // check for a default service and make sure it is at index 0. the lookupPrintServices does not // aways put the default printer first in the array. PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); if (defaultService != null && services.length > 1) { PrintService printService; for (int i = 1, max = services.length; i < max; i++) { printService = services[i]; if (printService.equals(defaultService)) { // found the default printer, now swap it with the first index. PrintService tmp = services[0]; services[0] = defaultService; services[i] = tmp; break; } } } return services; }
import java.awt.print.*; import javax.print.*; import javax.print.attribute.*; import java.text.*; import javax.print.attribute.standard.*; public class ShowPrinters { public ShowPrinters() { } public static void main(String[] args) { DocFlavor myFormat = DocFlavor.SERVICE_FORMATTED.PRINTABLE; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); PrintService[] services =PrintServiceLookup.lookupPrintServices(myFormat, aset); System.out.println("The following printers are available"); for (int i=0;i<services.length;i++) { System.out.println(" service name: "+services[i].getName()); } } }
PrintService[] printers = PrintServiceLookup.lookupPrintServices(FLAVOR, null); for (PrintService p : printers) { if (p.getName().equals(deviceName)) {
PrintService[] printers = PrintServiceLookup.lookupPrintServices(FLAVOR, null); for (PrintService p : printers) { if (p.getName().equals(deviceName)) {
Doc myDoc = new SimpleDoc(psStream, psInFormat, null); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);
PrintServiceLookup.lookupPrintServices(flavor, aset); int i; switch(pservices.length) {
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); PrintService[] pservices = PrintServiceLookup.lookupPrintServices( flavor, aset); int i;
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet (); PrintService [] pservices = PrintServiceLookup.lookupPrintServices (flavor, aset);
@Override public boolean print(byte[] content, JsonNode configuration, User user) { try { DocFlavor flavor = new DocFlavor("application/vnd.cups-raster", "[B"); for (PrintService service : PrintServiceLookup.lookupPrintServices(flavor, new HashPrintRequestAttributeSet())) { DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(content, flavor, null); job.print(doc, null); return true; } log.error("No printer found"); return false; } catch (PrintException e) { log.error("print", e); } return false; } },
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); for (PrintService printService : printServices) { if (printService.getName().trim().equals(printerName)) {
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); PrintService[] pservices = PrintServiceLookup.lookupPrintServices( flavor, aset); int i;
import java.io.FileInputStream; import javax.print.Doc; import javax.print.DocFlavor; import javax.print.DocPrintJob; import javax.print.PrintService; import javax.print.PrintServiceLookup; import javax.print.SimpleDoc; import javax.print.attribute.HashPrintRequestAttributeSet; import javax.print.attribute.PrintRequestAttributeSet; import javax.print.attribute.standard.Copies; public class Main { static public void main(String args[]) throws Exception { PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); PrintService pss[] = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, pras); if (pss.length == 0) throw new RuntimeException("No printer services available."); PrintService ps = pss[0]; System.out.println("Printing to " + ps); DocPrintJob job = ps.createPrintJob(); FileInputStream fin = new FileInputStream("YOurImageFileName.PNG"); Doc doc = new SimpleDoc(fin, DocFlavor.INPUT_STREAM.GIF, null); job.print(doc, pras); fin.close(); } }
PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);
private void printHelloDocument(String value) { PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.READER.TEXT_PLAIN; Doc doc = new SimpleDoc(new StringReader(value), flavor, null); PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, aset); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); if (services.length == 0) { if (defaultService == null) { new Notification("No printer found", WARNING_MESSAGE).show(getPage()); } else { DocPrintJob job = defaultService.createPrintJob(); printDocument(doc, aset, job); } } else { SwingUtilities.invokeLater(() -> { PrintService service = ServiceUI.printDialog(null, 200, 200, services, defaultService, flavor, aset); if (service != null) { DocPrintJob job = service.createPrintJob(); printDocument(doc, aset, job); } }); } }
public TableModel produce( final DataRow parameters, final DataFactoryContext dataFactoryContext ) throws ReportDataFactoryException { final PrintService[] services = PrintServiceLookup.lookupPrintServices( DocFlavor.SERVICE_FORMATTED.PAGEABLE, null ); final TypedTableModel tt = new TypedTableModel(); tt.addColumn( "Printer ID", String.class ); tt.addColumn( "Printer Name", String.class ); for ( int i = 0; i < services.length; i++ ) { final PrintService service = services[i]; final PrinterName displayName = service.getAttribute( PrinterName.class ); if ( displayName != null ) { tt.addRow( new Object[] { service.getName(), displayName.getValue() } ); } else { tt.addRow( new Object[] { service.getName(), service.getName() } ); } } return tt; } }