admin管理员组文章数量:1334288
While using browsers like Chrome and Firefox, there is an option to print the page to PDF (that is saving the webpage as a PDF file).
<a href="JavaScript:window.print();">Print this page</a>
This code opens up the print page from where the user should manually choose print to PDF. Can this be done automatically? If so please help.
While using browsers like Chrome and Firefox, there is an option to print the page to PDF (that is saving the webpage as a PDF file).
<a href="JavaScript:window.print();">Print this page</a>
This code opens up the print page from where the user should manually choose print to PDF. Can this be done automatically? If so please help.
Share Improve this question edited Nov 13, 2011 at 17:20 evotopid 5,4293 gold badges29 silver badges41 bronze badges asked Nov 13, 2011 at 17:14 PreetsPreets 1171 gold badge3 silver badges9 bronze badges3 Answers
Reset to default 2You can not print page to pdf with Javascript. You have to use server side script to print page to pdf. In PHP, you can use 3rd party PDF library like http://www.tcpdf .
There is not much available to print to PDF in Javascript.
The most supported option is indeed to generate it server-side using a library such as tcpdf (as shown by Thein Hla Maw).
I don't think Mark's solution is the correct one, since it requires the users to have some software installed.
For pure javascript PDF generation, there is this.
NB : thanks SO :-)
Yes... provided that your users have a few things installed.
- They need a PDF print driver, such as PrimoPDF
- If you want to automatically print to this driver, they need to have a plugin installed, such as JS Print Setup (for Firefox) or MeadCo ScriptX for IE
Then, using the API of said plugin, you can choose which driver to print to. You can even skip the print dialog.
A better option, however, would be the generate the PDF server-side, stream it to them, and then use JavaScript inside the PDF to automatically open the print dialog as soon as they view it. This way they don't need any plugins.
本文标签: javascriptAutomatically print a webpage to pdfStack Overflow
版权声明:本文标题:javascript - Automatically print a webpage to pdf - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742370637a2462168.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论