Search code examples
javascriptphpjqueryhtml2pdf

HTML2PDF automatic printing


Is there an easy way to get HTML2PDF to automatically open the print dialog window when outputting a pdf to the browser?

I tried setting javascript before output - Header conflict I tried after output of the PDF - No influence I tried within the PDF like TCPDF suggests (I thought HTML2PDF was built on this library) but it would not allow that due to no JS in PDF support.

Is there any other ways people know of or am I going to have to hack something with iframes or windows and declare print via that method?

Any help appreciated.


Solution

  • The printing depends on how you are letting the browser display the PDF. If you are letting the browser display them "normally" either a plugin (Adobe, FoxIT) or its native display of PDFs, then there is not much you can do, since you can't use JavaScript to access those.

    You could use pdf.js which renders the PDF using JavaScript on a canvas which you can print, see for example Printing PDF using pdf.js