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

4
  • possible duplicate of Converting HTML to PDF using PHP? Commented Aug 11, 2011 at 10:39
  • You mean, as in physically print on paper? Urgh! Commented Aug 11, 2011 at 11:18
  • This is not exactly the same, but it may help: stackoverflow.com/questions/6167995/… Commented Aug 11, 2011 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. Commented Aug 15, 2011 at 19:33

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.