Autoprint PDF script on php or javascript

12,004

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.

Share:
12,004

Related videos on Youtube

Vladimir
Author by

Vladimir

Updated on June 04, 2022

Comments

  • Vladimir
    Vladimir almost 2 years

    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

    • Brian
      Brian over 12 years
      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.

Related