如何在jsPDF中使用addHTML函数 [英] how to use addHTML function in jsPDF

查看:651
本文介绍了如何在jsPDF中使用addHTML函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何在jsPDF库中使用addHTML函数。我试图将网页转换为pdf。想要使用addHTML函数。让我知道需要传递哪些参数才能将整个网页转换为带有标题,徽标,正文等的pdf

解决方案

首先,你必须包括 jsPDF 库,以及 html2canvas rasterizeHTML



然后,只需创建一个jsPDF对象并将整个'body'标签(或其他)保存为pdf:



  var pdf = new jsPDF('p','pt','a4'); pdf.addHTML(document.body,function (){pdf.save('web.pdf');});  

 < script src =https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js>< / script>< script src =https: //cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js\"></script><body> < p id =to-pdf> HTML内容...< / p>< / body>  

<您可以在jsPDF网站上找到更多示例: http: //mrrio.github.io/jsPDF/


Could you please let me know how to use addHTML function in jsPDF libraries. Am trying to convert a webpage as pdf. want to use the addHTML function. Let me know what parameters need to be passed to get the entire webpage converted as pdf with header, logos, body etc

解决方案

First, you have to include jsPDF library, and also html2canvas or rasterizeHTML.

Then, just create a jsPDF object and save to pdf the entire 'body' tag (or whatever):

var pdf = new jsPDF('p','pt','a4');
pdf.addHTML(document.body,function() {
    pdf.save('web.pdf');
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.0.272/jspdf.debug.js"></script>

<body>
    <p id="to-pdf">HTML content...</p>
</body>

You can find more examples on the jsPDF website: http://mrrio.github.io/jsPDF/

这篇关于如何在jsPDF中使用addHTML函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆