This content has been marked as final. Show 17 replies
So how does creating .pdf files tell someone who already has one how to send the bindary data of the file from the server directly to a print driver on a client system and have the driver render and print the data correctly?
Something on the client system will have to read the binary data stream, render it as a .pdf, then create a spool file of some sort to pass off to the printer driver (probably in PostScript format.) Simplicity itself!
(This means I don't know how, either, but I'd be interested in a solution. If you're wanting to do this from a web browser, you're probably out of luck, but if you have a Java client receiving the file from the server, there's probably a way, however tangled.)
iText does the conversion to pdf, but I already have a pdf dokument (as a Java stream object) that I simply want to display and print (without displaying) on the client. I also don't want to save the stream to a file first and then pass the file to acrobat.
is there a way to do this? I tried the Acrobat java viewer which is very old and does not work at all.
I simply want to display and print (without displaying) on the client...Yes - first your applet must be trusted by the client PC (search these forums for details of signing your jar, and having the client trust the signer).
is there a way to do this?
Then have your applet write the stream to the disk as a file.
Finally invoke the AcroRd32.exe as an external process, pass /p and the file name (so your whole argument to the command line would be "C:\whever\acrobat\is\installed\AcroRd32.exe /p c:\temp\streamToFile.pdf").
You might have to play with the '/p' argument, I think it might have changed since I used it. Look at the adobe (www.adobe.com) site, and find the developer/sdk section. You'll have some research to do, but that's where I figured out how to do it...
i don't want to write a file but only to have a byte: is it possible?
If u r already using iText to generate PDF documents and don't wan't to write the generated PDF content to some xxx.pdf u can write data in to memeory and then stream it to the client by using the following line of code
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PdfWriter writer = PdfWriter.getInstance(document, byteArrayOutputStream);
These two line will make sure all the PDF contents stay in memory which could be later streamed to the client.
If in case u decide to write the content to a xxx.pdf file u can use the following line
PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("xxx.pdf"));
Coming back to printing the document with out user intervention u can achieve that too.
1. create a servlet which generates pdf content and store in the byte format
2. set the content type to the application.pdf
(i am assuming that u r working on web application)
If u can achieve this (I have done it, it is possible) your job is 90% done.
Here comes a bit of tweky work.
To print to the default printer:
To prompt the end user for the printer:
If you target the servlet response to a hidden frame, Acrobat Reader won't display, unless
the user elects to not embed it in the browser.
this old chestnut again - :)
Matthias - i suggest that you will have more luck printing using the InputStream flavours than with ByteArray. The same input sent via both flavours yielded a perfect result from the stream but printer confusion from the bytearray.
BTW - Apache FOP will silently prepare the PDF that you require, use the Driver.RENDER_PDF class.
Google Groups post on using the lpr command to do your PDF printing for you, apparently this works in UNIX and Windows 2000 or better:
i also faced the same problem as mention here, and i solved it as per your suggestions;
now comes to a point or situation in my web application:-
1. i want to save the generated pdf file in a file system, e.g. C:\test.pdf,
2. i also want to open it in browser to user and print it out without user intervention!
can it be achieved in anyway?
you can acheive the first requirement using Apache FOP. Simply get a PDF/PCL bytestream out of FOP and save that to a file.
If you have got solution for this can u suggest me.
I'm using following code
PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
DocFlavor flavor = javax.print.DocFlavor.INPUT_STREAM.AUTOSENSE;
PrintService printService = PrintServiceLookup.lookupPrintServices(flavor, pras);
PrintService defaultService = PrintServiceLookup.lookupDefaultPrintService();
PrintService service = ServiceUI.printDialog(null, 200, 200,printService, defaultService, flavor, pras);
if (service != null)
javax.print.attribute.standard.Copies obj=new javax.print.attribute.standard.Copies(1);
URL url = null;
url = new URL(urlToPDF);
fis = url.openStream();
DocPrintJob job = service.createPrintJob();
DocAttributeSet das = new HashDocAttributeSet();
Doc doc = new SimpleDoc(fis, flavor, null);
some times i'm getting garbage values in the printout.
Thanks & Regards,