最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - toDataURL() very slow - Stack Overflow

programmeradmin1浏览0评论

I have a report with charts and tables.
I am using the html2canvas with jsPDF to export this report to PDF file.

But the process is taking a long time, more than 11000ms.
I've tried to change the format, the quality, but nothing worked.

See below the code I used:

html2canvas($('#first-page'), {
    onrendered: function(canvas) {
        firstPage = canvas.toDataURL('image/jpeg', 0.5);
    },
    background: '#ffffff'
});


I'm doing something wrong or really is a problem?
How I can improve the performance?

I have a report with charts and tables.
I am using the html2canvas with jsPDF to export this report to PDF file.

But the process is taking a long time, more than 11000ms.
I've tried to change the format, the quality, but nothing worked.

See below the code I used:

html2canvas($('#first-page'), {
    onrendered: function(canvas) {
        firstPage = canvas.toDataURL('image/jpeg', 0.5);
    },
    background: '#ffffff'
});


I'm doing something wrong or really is a problem?
How I can improve the performance?

Share Improve this question edited Jul 5, 2017 at 17:28 Michel Makei Gefuni asked Jul 5, 2017 at 14:03 Michel Makei GefuniMichel Makei Gefuni 1671 gold badge2 silver badges13 bronze badges 7
  • Have you verified that is it actually this step that takes so much time? I’d imagine that rendering your content onto the canvas is gonna take a good amount of time as well ... – C3roe Commented Jul 5, 2017 at 14:13
  • How big is the image? – Blindman67 Commented Jul 5, 2017 at 14:20
  • @CBroe I did not think about this step, of rendering the html inside the canvas. How can I measure this time? – Michel Makei Gefuni Commented Jul 5, 2017 at 14:33
  • 1 stackoverflow./questions/313893/… – C3roe Commented Jul 5, 2017 at 14:35
  • 1 Maybe the problem be the plugin html2canvas, in the step render the content onto the canvas – Michel Makei Gefuni Commented Jul 5, 2017 at 14:41
 |  Show 2 more ments

1 Answer 1

Reset to default 5

You don't need to use toDataUrl.http://jsfiddle/davidmather/sxp0meer/3/

html2canvas($('#first-page'), {
onrendered: function(canvas) {            
    var doc = new jsPDF('p', 'mm');
    doc.addImage(canvas, 'PNG', 10, 10);
    doc.save('sample-file.pdf');
}
});
发布评论

评论列表(0)

  1. 暂无评论