I have a web application that has a requirement to silent print a generated pdf (the user should not even see the pdf). I tried basing my code on the sample code from the iText site:
// setting some response headers response.setHeader("Expires", "0"); response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); response.setHeader("Pragma", "public"); // setting the content type response.setContentType("application/pdf"); // the content length is needed for MSIE!!! response.setContentLength(baos.size());
// write ByteArrayOutputStream to the ServletOutputStream ServletOutputStream out = response.getOutputStream(); baos.writeTo(out); out.flush();
No luck, the pdf is generated (and opens which I don't want) and will not print!
The code you posted doesn't print anything - it streams a PDF file to a browser. That the file contains code to print it under certain circumstances is irrelevant. A few things to consider in this situation:
Without opening the file there's no chance of it being printed, since the embedded print code depends on the file being opened.
Whether the file is opened is not under the control of the web app. The user may have set the browser to save PDF files w/o opening them.
If it is opened, it will be displayed. No way around that, at least not with common viewers like Adobe Reader or OS X Preview.
Given these, I think what you're trying to achieve is not possible. I'd argue that's a good thing, too, since printing something on a client system w/o the user noticing it is not a nice thing to do. Maybe in your situation it's acceptable or even desirable, but in general it's not, which is why it doesn't work that way.
What is the rationale for wanting to do this? [ April 03, 2008: Message edited by: Ulf Dittmer ]
I am also interested in silent printing with iText.
However I did not find any solution.