i require to send a pdf document to print on the server side of a web app, the printer fully supports pdf printing etc, it is networked as well to the server. The pdf is also stored on the server. what i am trying to is on a button click, print out the pdf file, currently i have the code below :
//Server side printing public class PrintDocument < public void printText(String text) throws PrintException, IOException < //Looks for all printers //PrintService[] printServices = PrinterJob.lookupPrintServices(); PrintService service = PrintServiceLookup.lookupDefaultPrintService(); InputStream is = new ByteArrayInputStream(text.getBytes("UTF8")); PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet(); pras.add(new Copies(1)); DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE; Doc doc = new SimpleDoc(is, flavor, null); DocPrintJob job = service.createPrintJob(); PrintJobWatcher pjw = new PrintJobWatcher(job); job.print(doc, pras); pjw.waitForDone(); is.close(); >> class PrintJobWatcher < boolean done = false; PrintJobWatcher(DocPrintJob job) < job.addPrintJobListener(new PrintJobAdapter() < public void printJobCanceled(PrintJobEvent pje) < allDone(); >public void printJobCompleted(PrintJobEvent pje) < allDone(); >public void printJobFailed(PrintJobEvent pje) < allDone(); >public void printJobNoMoreEvents(PrintJobEvent pje) < allDone(); >void allDone() < synchronized (PrintJobWatcher.this) < done = true; System.out.println("Printing has successfully completed, please collect your prints)"); PrintJobWatcher.this.notify(); >> >); > public synchronized void waitForDone() < try < while (!done) < wait(); >> catch (InterruptedException e) < >> >
But i have a few questions / issues, how do i put the pdf into the input stream for this to be printed out, can i select options such as duplex printing, and how can i call this from inside a JSF web app Thanks