admin管理员组

文章数量:1334667

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?

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?

Share Improve this question asked Jul 10, 2010 at 5:36 Bali DaveBali Dave 1711 gold badge2 silver badges9 bronze badges 4
  • So the scenario is as follows: click a link, and a print prompt box appears? Absolutely NOTHING in between? – kamasheto Commented Jul 10, 2010 at 5:39
  • Yes, either a link or a button that would be on a "normal page" having much other info, but just offering this Print button/link as an option to the user. – Bali Dave Commented Jul 10, 2010 at 6:07
  • If your goal is to make it so the user can't save the PDF, give up now. Even if you somehow force them to print it, the "printer" can actually be a program writing to a PDF on their local disk. – Borealid Commented Jul 10, 2010 at 7:19
  • No, saving is fine -- the main goal is for the user to have quick access to printing this pdf and automate that as much as possible. – Bali Dave Commented Jul 11, 2010 at 3:32
Add a ment  | 

3 Answers 3

Reset to default 6

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.

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.

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.

本文标签: javascriptNeed a print button in a browser that will print a PDF fileStack Overflow