List of usage examples for javax.print DocPrintJob print
public void print(Doc doc, PrintRequestAttributeSet attributes) throws PrintException;
From source file:PrintServiceTest.java
public static void main(String[] args) { DocFlavor flavor = DocFlavor.URL.GIF; PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null); if (args.length == 0) { if (services.length == 0) System.out.println("No printer for flavor " + flavor); else {//w ww . j av a 2s . c o m System.out.println("Specify a file of flavor " + flavor + "\nand optionally the number of the desired printer."); for (int i = 0; i < services.length; i++) System.out.println((i + 1) + ": " + services[i].getName()); } System.exit(0); } String fileName = args[0]; int p = 1; if (args.length > 1) p = Integer.parseInt(args[1]); try { if (fileName == null) return; FileInputStream in = new FileInputStream(fileName); Doc doc = new SimpleDoc(in, flavor, null); DocPrintJob job = services[p - 1].createPrintJob(); job.print(doc, null); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (PrintException e) { e.printStackTrace(); } }
From source file:StreamOneFour.java
public static void main(String args[]) throws Exception { String infile = "StreamOneFour.java"; DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; String mimeType = DocFlavor.INPUT_STREAM.POSTSCRIPT.getMimeType(); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, mimeType);/*w w w. j a va2 s . c o m*/ String filename = "out.ps"; FileOutputStream fos = new FileOutputStream(filename); StreamPrintService sps = factories[0].getPrintService(fos); FileInputStream fis = new FileInputStream(infile); DocPrintJob dpj = sps.createPrintJob(); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); Doc doc = new SimpleDoc(fis, flavor, null); dpj.print(doc, pras); fos.close(); }
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];//from w w w . ja v a2 s. c o m 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(); }
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); }
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];// w ww . ja v a2 s . c o m 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(); }
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); pjDone.waitForDone();//from w w w .j a v a 2 s . com is.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); job.print(doc, null); pjDone.waitForDone();/* ww w . java 2s . c o m*/ is.close(); }
From source file:PrintImage.java
static public void main(String args[]) throws Exception { try {//from w ww.ja va2 s . co m 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")); OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); if (factories.length > 0) { StreamPrintService service = factories[0].getPrintService(fos); DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); job.print(doc, null); pjDone.waitForDone();/*from ww w. jav a2s .c o m*/ } is.close(); fos.close(); }
From source file:Main.java
public static void main(String[] argv) throws Exception { OutputStream fos = new BufferedOutputStream(new FileOutputStream("filename.ps")); DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; InputStream is = new BufferedInputStream(new FileInputStream("filename.gif")); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType()); StreamPrintService service = factories[0].getPrintService(fos); final DocPrintJob job = service.createPrintJob(); Doc doc = new SimpleDoc(is, flavor, null); PrintJobWatcher pjDone = new PrintJobWatcher(job); if (job instanceof CancelablePrintJob) { CancelablePrintJob cancelJob = (CancelablePrintJob) job; try {/*from w w w. ja v a2 s. c o m*/ cancelJob.cancel(); } catch (PrintException e) { } } job.print(doc, null); pjDone.waitForDone(); is.close(); }