6

I want to build a page that will automatically print a pdf document. For example I can call mypage.html?doc=my.pdf and it will print my.pdf file.

How I can do it using javascript or php?

Vladimir

midhunhk
  • 5,560
  • 7
  • 52
  • 83
Vladimir
  • 173
  • 1
  • 2
  • 14
  • possible duplicate of [Converting HTML to PDF using PHP?](http://stackoverflow.com/questions/733219/converting-html-to-pdf-using-php) – cweiske Aug 11 '11 at 10:39
  • You mean, as in physically print on paper? Urgh! – Richard H Aug 11 '11 at 11:18
  • This is not exactly the same, but it may help: http://stackoverflow.com/questions/6167995/generate-a-pdf-that-automatically-prints/6168091#6168091 – yms Aug 11 '11 at 12:26
  • 1
    You can't make the browser immediately offer the user the option of printing a PDF file, but you can output a PDF using a method provided by one of the users above. From there the user can opt to click the print button on their own (or choose to open/save the PDF depending on the headers you use). But to directly answer your question, there's no way to do what you want. – Brian Aug 15 '11 at 19:33

1 Answers1

3

The closest you can get to what you want is to embed an iframe containing the PDF in an HTML page, then call window.print when the iframe has loaded.

...
<iframe src="path/to/file.pdf" onload="window.print()"></iframe>
...

This will open the standard print dialog on most browsers.

Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
Matthew
  • 15,464
  • 2
  • 37
  • 31