html网页导出pdf的js插件
引入js库<script type="text javascript" src="html2pdf html2canvas js">< script><script type="text javascript" src="html2pdf jsP
引入js库
<script type="text/javascript" src="html2pdf/html2canvas.js"></script>
<script type="text/javascript" src="html2pdf/jsPdf.debug.js"></script>
JS代码
<script type="text/javascript">var downPdf = document.getElementById("renderPdf");downPdf.onclick = function() {html2canvas(document.body, {onrendered:function(canvas) {//返回图片URL,参数:图片格式和清晰度(0-1)var pageData = canvas.toDataURL('image/jpeg', 1.0);//方向默认竖直,尺寸ponits,格式a4【595.28,841.89]var pdf = new jsPDF('', 'pt', 'a4');//需要dataUrl格式pdf.addImage(pageData, 'JPEG', 0, 0, 595.28, 592.28/canvas.width * canvas.height );pdf.save('content.pdf');}})}
html代码:
<button id="renderPdf">DOWNLOAD PDF</button>