posted 16 years ago
Welcome to JavaRanch.
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. If the client PDF viewer supports JavaScript (which is not a given - it may be disabled, or a viewer may be used that doesn't support it), and the code runs, a print dialog will be displayed that will require the user to click at least one button. No way around that either.
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 ]