问题描述
您好我使用jsPdf制作pdf的html内容,它的内容很短,并创建pdf,但是当我试图使用它与大的内容与html2canvas.js(用于渲染css),它不是创建pdf。
任何建议或示例代码都会有帮助。谢谢。
Hi I am using jsPdf for making pdf of html content, it is going fine for short content and creating pdf , but when I am trying to use it on large content with html2canvas.js (for rendering css), it is not creating pdf.Any suggestions or sample code for this would be helpful.Thank you.
推荐答案
大型文件。主要有两种方法:
It is possible to create pdf for large files. There are primarily two ways to do this :
1。 html - > canvas - > image - > pdf (我假设你正在尝试这种方法)
1. html -> canvas -> image -> pdf (I assume you are trying this approach)
2。 html - > pdf (如果html包含svg,则无效)
2. html -> pdf (does not work if html contains svg)
我建议你去(2)(1)(如果你有svg内容) - 这是相当昂贵的操作浏览器,有浏览器崩溃的可能性。
I would suggest you to go for (2) unless you have a good reason to go for (1) (like if you are have svg content)-- it is quite expensive operation for the browser and there is possibility of the browser crashing too.
1。 html - > canvas - > image - > pdf
这里非常整齐地描述 -
This is very neatly described here - https://github.com/MrRio/jsPDF/issues/339#issuecomment-53327389
我使用这种方法的经验 - 当生成的pdf包含超过2-3页时崩溃。 (在最新的chrome和Firefox上测试)
My experience when using this method - crashes when the pdf generated contains more than 2-3 pages. (tested on latest chrome and firefox)
2。 html - > pdf
var pdf = new jsPDF('l', 'pt', 'a4');
var options = {
pagesplit: true
};
pdf.addHTML($('body'), 0, 0, options, function(){
pdf.save("test.pdf");
});
与上述方法相比,这种方法更快。在1-2秒内生成包含5-6页的pdf!
This is way faster compared to above approach. Generates pdf containing 5-6 pages in 1-2 seconds!
希望这有助于!
这篇关于jsPdf使用html2canvas.js从html导出pdf不适用于大数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!