Question
Last activity: 10 Jun 2016 7:03 EDT
Auto or Silent Print a PDF byte Array using default Printer by disabling Print Dialogue.
Auto or Silent Print a PDF byte Array using default Printer by disabling Print Dialogue.
Message was edited by: Lochan to add Category
Hi Gurushankar,
You might want to look at these two third-party examples (I have not tried them) : these show how to use Microsoft Powershell (actually it's just using Adobe Acrobat as a program) and Java to print a PDF to the default printer; in theory you could wrap up these in a PRPC Activity* - assuming it would be acceptable to issue the print job from the back-end not the the user's desktop ?
http://stackoverflow.com/questions/7246560/print-automatically-pdf-file-with-powershell
The above suggests something like the following Powershell (but there are other linked examples using Foxit referenced as well):
Start-Process -FilePath "test.pdf" –Verb Print sleep 10 kill -name AcroRd32
I couldn't find a decent example of printing PDF files from Java, but here's a starter (it uses a PDF Java Library by the look of it):
http://stackoverflow.com/questions/35535589/java-how-to-print-the-pdf-to-a-specific-printer/35535726
If you are running PRPC in Linux environment; you might want to use some the 'pdf2dsc' commandline (to convert PDF to PostScript, which you should then be able to print. (again: I have not tried this).
It sounds like you are working with PDFBytes rather than PDFFiles here: so you would need to write these bytes to a temporary file (probably) before using any of these approaches.
Cheers
John
* I'm also not entirely sure of the best way of 'wrapping' up a Powershell call from Java: but you could perhaps create a Powershell script to 'poll' for a file on-disk (created by a PRPC Activity File Connector maybe).
Hi John Pritchard-williams.. thank you for the timely reply..
We have tried below code and seems to be working in eclipse. When we tried importing JAR(java-rt-jar-stubs-1.5.0.jar) containing javax.print.* and java.awt.print.*, we are getting UNKNOWN archive type error. Except this we are good with code.
import javax.print.*;
import java.awt.print.PrinterException;
import java.awt.print.PrinterJob;
// Put a Sample PDF Stream
String pdfStream = "JVBERi0xLjcNJeLjz9MNCjggMCBvYmoNP";
// Convert the Stream to bytes
byte[] Pdfbytes = Base64Util.decodeToByteArray(pdfStream);
// Set Doc Flavor to PDF
DocFlavor flavor = DocFlavor.BYTE_ARRAY.PDF;
// Look Up Defualt Print Service
PrintService[] services = PrintServiceLookup.lookupDefaultPrintService(flavor, null);
// Create a print Job
DocPrintJob printJob = services.createPrintJob();
// Create a sample Document
Doc document = new SimpleDoc(Pdfbytes, flavor, null);
// Issue Print
printJob.print(document, null);
Idea is to not download the PDF in client and allow it to print with print dialogue rather send the payload to default printer. Any help is greatly appreciated. Saleem AbdelsayedBrendan Horan