Printing a PDF document using java without FileInputStream

385 Views Asked by At

I have a generated document using iText library in java using the next code:

        Document document = new Document();
        document.open();

I manipulate the document with adding tables and data to it. Now i want to print the document after all; I found a way to send the document to the printer using the following code, but with using Input stream:

        InputStream inputStream = new FileInputStream("C://Housing Report(1).pdf");
         Doc doc = new SimpleDoc(inputStream, 
         DocFlavor.INPUT_STREAM.AUTOSENSE,null);

         PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();  
         PrintService services = 
         PrintServiceLookup.lookupDefaultPrintService();  


         DocPrintJob job = services.createPrintJob();  
         try {  
         job.print(doc, aset);  

         } catch (Exception pe) {pe.printStackTrace();}  

}  

My question is how can I print the iText document without having to save it and using InputStream to print it again? Thanks in advance.

0

There are 0 best solutions below