question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

toDataURL() very slow

See original GitHub issue

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.

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?

EDIT: I discovered the problem isn’t toDataURL() method, but is the process to render the content onto the canvas, but, the problem continues.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:4
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

39reactions
abhinavkumar985commented, Mar 19, 2019

It is still slow in 2019, when extracting 5-6 html content into pdf with html2canvas.

0reactions
mohdrashidreactcommented, Jun 8, 2022

how can I make it fast in react in any idea.

function generatePdf() { toggleIspdfSaving(true); setTimeout(() => { try { const input = document.getElementById(“report-page”); html2canvas(input, { logging: true, letterRendering: 1, useCORS: true, windowWidth: 1920, windowHeight: 1080, allowTaint:true, }) .then((canvas) => { console.log(“testing … time”,canvas.height); const imgWidth = 270; const imgHeight = (canvas.height * imgWidth) / canvas.width; const imgData = canvas.toDataURL(“img/jpeg”,0.5); const pdf = new jsPDF(“p”, “px”, [202, imgHeight]); pdf.addImage(imgData, “PNG”, 0, 0, imgWidth, imgHeight,undefined,‘FAST’); // pdf.addImage(imgData, ‘PNG’, 0, 0, imgWidth, imgHeight); pdf.save( ${outputDetail?.name}-version-${outputDetail?.version}-report ); toggleIspdfSaving(false); dispatch( toastNotificationAction.initiateToastDisplay({ text: “Summary exported successfully”, toastType: “success”, }) ); }) .catch((error) => { console.log(“error in exporting summary”, error); toggleIspdfSaving(false); dispatch( toastNotificationAction.initiateToastDisplay({ text: “Unable to export summary”, toastType: “error”, }) ); }); } catch (err) { toggleIspdfSaving(false); dispatch( toastNotificationAction.initiateToastDisplay({ text: “Unable to export summary”, toastType: “error”, }) ); } }, 100); }

Read more comments on GitHub >

github_iconTop Results From Across the Web

javascript - Why toDataURL is so slow?
If I transfer a simple image through the network, it's fast. When I try to transfer the same image created in a canvas...
Read more >
Canvas toDataURL takes too long and blocks the browser
The time taken to execute toDataURL() call is roughly 40 times longer in Chrome than in Firefox 4 or Safari 5 ... It...
Read more >
Javascript – Why toDataURL is so slow
If I transfer a simple image through the network, it's fast. When I try to transfer the same image created in a canvas...
Read more >
Canvas operations really slow : r/javascript
Okay, guys, so I have a tool I made to auto generate a chart from data with ... toDataURL() + '" target="_blank"><img src="'...
Read more >
HTMLCanvasElement.toBlob() - Web APIs | MDN
toBlob() method creates a Blob object representing the image ... If the file format is not specified, or if the given format is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found