新科展教育

                                          新科展教育

                                          ┃ 新科展教育 > 新闻热点 >

                                          使用html2pdf.js将HTML页面生成PDF

                                          html2pdf.js converts any webpage or element into a printable PDF entirely client-side using html2canvas and jsPDF.

                                          崔素强博客使用

                                          正在html2pdf.js中陪衬进程是由html转称canvas,再由canvas转成pdf,然则作家懂得指出正在html5中canvas拥有最年夜下度战阔度,超越最年夜限制就没法停止挨印。

                                          The basic workflow of html2pdf.js tasks (enforced by the prereq system) is:

                                          .from()->.toContainer()->.toCanvas()->.toImg()->.toPdf()->.save()

                                          停载天址:

                                          https://github.com/eKoopmans/html2pdf.js

                                          民圆文档:

                                          https://ekoopmans.github.io/html2pdf.js/

                                          canvas限定各个阅读器增援环境:

                                          Chrome:Maximumheight/width:32,767pxMaximumarea:268,435,456px(比方,16,384x16,384)Firefox:Maximumheight/width:32,767pxMaximumarea:472,907,776px(比方,22,528x20,992)IE:Maximumheight/width:8,192pxMaximumarea:N/AIEMobile:Maximumheight/width:4,096pxMaximumarea:N/A

                                          依照民圆示例编写1个尝试页里:

                                          <!DOCTYPEHTML><html><head><title>HTML转PDF尝试</title><metaname="viewport"content="width=device-width,initial-scale=1.0"/><styletype="text/css">/*Basicstylingforroot.*/#root{width:500px;height:700px;background-color:yellow;}</style></head><body><buttononclick="test()">死成PDF</button><divid="root">尝试内乱容</div><scriptsrc="html2pdf.bundle.js"></script><script>functiontest(){//获得DIV元素varelement=document.getElementById('root');//死成PDF挪用html2pdf().from(element).set({margin:1,filename:'test.pdf',html2canvas:{scale:2},jsPDF:{orientation:'portrait',unit:'in',format:'letter',compressPDF:true}}).save();}</script></body></html>

                                          END

                                          推举您浏览更多相关于“ jshtmlhtml2pdfPDF ”的著作

                                          电话咨询 联系我们 在线沟通 查看地图