Spec-Zone .ru
спецификации, руководства, описания, API
|
DocFlavor psFlavor = DocFlavor.INPUT_STREAM.POSTSCRIPT; PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(2)); aset.add(MediaSizeName.ISO_A4); aset.add(Sides.TWO_SIDED_LONG_EDGE); aset.add(Finishings.STAPLE); PrintService[] pservices = PrintServiceLookup.lookupPrintServices(psFlavor, aset); if (services.length > 0) { DocPrintJob pj = pservices[0].createPrintJob(); try { FileInputStream fis = new FileInputStream("example.ps"); Doc doc = new SimpleDoc(fis, psFlavor, null); pj.print(doc, aset); } catch (IOException e) { System.err.println(e); } catch (PrintException e) { System.err.println(e); } }См. Пример: PrintPS.java для полного приложения.
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF; String psMimeType = DocFlavor.BYTE_ARRAY.POSTSCRIPT.getMimeType(); PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet(); aset.add(new Copies(2)); aset.add(MediaSizeName.ISO_A4); aset.add(Sides.TWO_SIDED_LONG_EDGE); aset.add(Finishings.STAPLE); StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories( flavor, psMimeType); if(factories.length==0) { System.err.println("No suitable factories"); System.exit(0); } try { FileInputStream fis = new FileInputStream("java2dlogo.gif"); String filename = "newfile.ps"; FileOutputStream fos = new FileOutputSteam(filename); StreamPrintService sps= factories[0].getPrintService(fos); DocPrintJob pj = sps.createPrintJob(); Doc doc = new SimpleDoc(fos, psFlavor, aset); pj.print(doc, aset); } catch (IOException e) { System.err.println(e); } catch (PrintException e) { System.err.println(e); } }См. Пример: PrintGIFtoStream.java для полного приложения.