List of usage examples for javax.print PrintServiceLookup lookupDefaultPrintService
public static final PrintService lookupDefaultPrintService()
From source file:ImagePrint.java
public static void main(String[] args) throws Exception { PrintService service = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = service.createPrintJob(); DocFlavor flavor = DocFlavor.SERVICE_FORMATTED.PRINTABLE; SimpleDoc doc = new SimpleDoc(new MyPrintable(), flavor, null); job.print(doc, null);//www.jav a 2 s.c o m }
From source file:Main.java
public static void main(String[] argv) throws Exception { PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); services = PrintServiceLookup.lookupPrintServices(DocFlavor.INPUT_STREAM.GIF, null); AttributeSet aset = new HashAttributeSet(); aset.add(new PrinterName("HP LaserJet", null)); services = PrintServiceLookup.lookupPrintServices(null, aset); aset = new HashAttributeSet(); aset.add(ColorSupported.SUPPORTED); services = PrintServiceLookup.lookupPrintServices(null, aset); }
From source file:Main.java
public static void main(String[] args) throws Exception { InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService service = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); job.print(doc, null);/*from w w w . j a va 2 s . co m*/ pjDone.waitForDone(); is.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { String filename = args[0];/* www.j av a 2 s . c om*/ DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); DocPrintJob job = printService.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.out.println("Good-bye"); System.exit(0); } }; job.addPrintJobListener(listener); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); }
From source file:OneFourDialog.java
public static void main(String args[]) throws Exception { String filename = args[0];//ww w . j a v a 2 s . c o m PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; PrintService printService[] = PrintServiceLookup.lookupPrintServices(flavor, pras); PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); PrintService service = ServiceUI.printDialog(null, 200, 200, printService, defaultService, DocFlavor.INPUT_STREAM.GIF, pras); if (service != null) { DocPrintJob job = service.createPrintJob(); PrintJobListener listener = new PrintJobAdapter() { public void printDataTransferCompleted(PrintJobEvent e) { System.exit(0); } }; job.addPrintJobListener(listener); FileInputStream fis = new FileInputStream(filename); DocAttributeSet das = new HashDocAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, das); job.print(doc, pras); Thread.sleep(10000); } }
From source file:Main.java
public static void imprimirFactura(String factura) throws PrintException { PrintService service = PrintServiceLookup.lookupDefaultPrintService(); if (service == null) { throw new PrintException("No se encontro impresora conectada"); }/*w w w. j a va 2s. c o m*/ //Le decimos el tipo de datos que vamos a enviar a la impresora //Tipo: bytes Subtipo: autodetectado DocFlavor flavor = DocFlavor.BYTE_ARRAY.AUTOSENSE; DocPrintJob pj = service.createPrintJob(); byte[] bytes; bytes = factura.getBytes(); Doc doc = new SimpleDoc(bytes, flavor, null); pj.print(doc, null); }
From source file:ru.trett.cis.services.PrinterServiceImpl.java
@Override public String print(String file) throws ApplicationException, FileNotFoundException, PrintException { DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(MediaSizeName.ISO_A4); PrintService printServices = PrintServiceLookup.lookupDefaultPrintService(); if (printServices == null) throw new ApplicationException("Default printer not found"); LOGGER.info("Default printer is " + printServices.getName()); DocPrintJob printJob = printServices.createPrintJob(); FileInputStream fis = new FileInputStream(file); Doc doc = new SimpleDoc(fis, flavor, null); printJob.print(doc, aset);//ww w . j ava 2 s. c o m return printServices.getName(); }
From source file:org.obiba.onyx.print.PdfPrintingService.java
public void afterPropertiesSet() throws Exception { // Try to find a PrintService instance with the specified name if any if (printerName != null && printerName.length() > 0) { log.info("Looking for a printer named '{}'", printerName); // Lookup all services PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); for (PrintService ps : printServices) { if (ps.getName().equalsIgnoreCase(printerName)) { log.info("Using printer '{}'", ps.getName()); this.printService = ps; break; }// ww w . j a va2 s.c o m } if (printService == null) { log.warn("Could not find printer with name '{}'. Will try default printer.", printerName); } } // If the printService is null, we weren't configured with a printerName or we couldn't // find one with the specified name if (printService == null) { printService = PrintServiceLookup.lookupDefaultPrintService(); if (printService != null) { log.info("Using default printer '{}'.", printService.getName()); } } // If the printService is null, there is no default printer installed. if (printService == null) { log.warn("No default printer found. Printing will not be available."); } else { // We have a PrintService instance. Find the first handler that this service accepts. for (PdfHandler handler : IMPLEMENTED_FLAVORS) { if (printService.isDocFlavorSupported(handler.getImplementedFlavor())) { supportedHandler = handler; break; } } if (supportedHandler != null) { log.info("Printer '{}' supports PDF printing through handler {}. PDF printing will be available.", printService.getName(), supportedHandler.getClass().getSimpleName()); } else { log.warn( "Printer '{}' does not support printing PDF files directly. PDF printing will not be available.", printService.getName()); printService = null; } } }
From source file:com.floreantpos.jasperreport.engine.print.JRPrinterAWT.java
/** * Fix for bug ID 6255588 from Sun bug database * @param job print job that the fix applies to *///from ww w . j av a 2 s. c o m public static void initPrinterJobFields(PrinterJob job) { try { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); PrintService printService = PrintServiceLookup.lookupDefaultPrintService(); for (int i = 0; i < printServices.length; i++) { PrintService service = printServices[i]; if (service.getName().equals(printerName)) { printService = service; break; } } job.setPrintService(printService); } catch (PrinterException e) { } }
From source file:de.cenote.jasperstarter.App.java
private void listPrinters() { PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService(); System.out.println("Default printer:"); System.out.println("-----------------"); System.out.println((defaultService == null) ? "--- not set ---" : defaultService.getName()); System.out.println(""); PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Available printers:"); System.out.println("--------------------"); for (PrintService service : services) { System.out.println(service.getName()); }/*from w w w . j a v a 2s . co m*/ }