Javascript 如何在jsPDF中使用addHTML函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28193487/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to use addHTML function in jsPDF
提问by Shireesh
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
您能否让我知道如何在 jsPDF 库中使用 addHTML 函数。我正在尝试将网页转换为 pdf。想使用 addHTML 函数。让我知道需要传递哪些参数才能将整个网页转换为带有标题、徽标、正文等的 pdf
回答by gonzaloriestra
First, you have to include jsPDFlibrary, and also html2canvasor rasterizeHTML.
首先,您必须包含jsPDF库,以及html2canvas或rasterizeHTML。
Then, just create a jsPDF object and save to pdf the entire 'body' tag (or whatever):
然后,只需创建一个 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 content...</p>
</body>
You can find more examples on the jsPDF website: http://mrrio.github.io/jsPDF/
您可以在 jsPDF 网站上找到更多示例:http://mrrio.github.io/jsPDF/

