List of usage examples for javax.print PrintService createPrintJob
public DocPrintJob createPrintJob();
From source file:PrintImage.java
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);//from www.j ava2 s . co m fin.close(); }
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);/*w ww .ja va 2 s . c om*/ }
From source file:Main.java
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);//w ww .j a v a2s . c om fin.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { String filename = args[0];// w ww . j a v a 2 s . c o m 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:PrintImage.java
static public void main(String args[]) throws Exception { try {/*from w w w. j ava 2 s . com*/ 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(); } catch (IOException ie) { ie.printStackTrace(); } catch (PrintException pe) { pe.printStackTrace(); } }
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 v a 2 s . c o m*/ pjDone.waitForDone(); is.close(); }
From source file:OneFourDialog.java
public static void main(String args[]) throws Exception { String filename = args[0];//from ww w. j a v a2 s. com 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"); }/*from w ww. j ava2 s.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:net.sourceforge.fenixedu.util.report.ReportsUtils.java
private static void print(PrintService printService, byte[] pdf) throws PrintException { final DocPrintJob job = printService.createPrintJob(); final Doc doc = new SimpleDoc(pdf, DocFlavor.BYTE_ARRAY.PDF, null); final PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(1)); aset.add(MediaSizeName.ISO_A4); aset.add(Sides.ONE_SIDED);/* w ww . j a v a 2 s. c o m*/ job.print(doc, aset); }
From source file:Print.java
public static void printToService(PrintService service, String filename, PrintRequestAttributeSet attributes) throws IOException { // Figure out what type of file we're printing DocFlavor flavor = getFlavorFromFilename(filename); // Open the file InputStream in = new FileInputStream(filename); // Create a Doc object to print from the file and flavor. Doc doc = new SimpleDoc(in, flavor, null); // Create a print job from the service DocPrintJob job = service.createPrintJob(); // Monitor the print job with a listener job.addPrintJobListener(new PrintJobAdapter() { public void printJobCompleted(PrintJobEvent e) { System.out.println("Print job complete"); System.exit(0);// w ww.j ava 2s . c o m } public void printDataTransferCompleted(PrintJobEvent e) { System.out.println("Document transfered to printer"); } public void printJobRequiresAttention(PrintJobEvent e) { System.out.println("Print job requires attention"); System.out.println("Check printer: out of paper?"); } public void printJobFailed(PrintJobEvent e) { System.out.println("Print job failed"); System.exit(1); } }); // Now print the document, catching errors try { job.print(doc, attributes); } catch (PrintException e) { System.out.println(e); System.exit(1); } }