Doc
and DocPrintJob
, you can call the DocPrintJob
object's print
method to submit the document to the service. The Submitting the Print Job to the
Printer section completes the printing example. The
Submitting the Print Job to
the Stream section completes the streaming example.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); } }See Example: PrintPS.java for the complete application.
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); } }See Example: PrintGIFtoStream.java for the complete application.