views:

102

answers:

3

I need to set up a print button in HTML that will print a certain PDF file, hopefully without having to download the file first. I've tried a few things but some only work in IE. and some require downloading the file as an embedded object which also is not acceptable. Embedding javascript in the PDF sounds the most promising, but I'd rather avoid that if possible for other reasons.

Any other ideas?

+3  A: 

Unfortunately it really can't be done... PDFs are not handled naively by any browser, and as is such they can't be printed using the browser's print dialog.

Your users will have to download the pdf and print it with whatever PDF software they use (Even if it's just a plugin for the browser) unless you convert it to boring old html or an image or something.

Sushisource
Embedding javascript in the pdf will work, at least for many machines (I heard of some problems with Macs on that -- anybody know anymore?). That may be my only realistic option.
Bali Dave
A: 

You cannot print something without the user downloading it first.

The printer is located on the user end of the connection. The PDF is, at first, located on the server end.

The PDF must thus travel across the webs to reach the user end before the printer will know which ink to put on paper. In other words, it must be downloaded.

Borealid
I understand that, but don't want to download the file BEFORE the user has hit the Print button, because he might NOT want to print it.
Bali Dave
A: 

I think the best you can do is download the PDF into an iframe element, and advise the user to click the "print" button in there. To my knowledge, no tighter integration than that is possible. The PDF viewer's print button can not be accessed via JavaScript.

Pekka