List of usage examples for javax.print PrintException getCause
public synchronized Throwable getCause()
From source file:Main.java
public static void main(String[] argv) throws Exception { try {/*from ww w . j a v a 2 s.c o m*/ 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 { cancelJob.cancel(); } catch (PrintException e) { } } job.print(doc, null); pjDone.waitForDone(); is.close(); } catch (PrintException e) { if (e.getCause() instanceof PrinterAbortException) { System.out.println("Print job was cancelled"); } } }