0

I'm trying to use html2canvas library (version 1.4.1) with React 17 to download html as a picture and pdf. I think there is a problem with box-shadows. Here is the code I use to download pictures and pdf:

const downloadChart = (divElement: HTMLElement) => {
        html2canvas(divElement)
        .then((canvas) => {
            const imgData = canvas.toDataURL('image/png');
            if (chartId) {
                const link = document.createElement('a');
                link.href = imgData;
                link.download = chartId + '.png';
                link.click();
            } else {
                var doc = new jsPDF('p', 'mm', 'a4');
                const imgWidth = 210;
                const imgHeight = (canvas.height * imgWidth) / canvas.width;
                doc.addImage(imgData, 'PNG', 0, 10, imgWidth, imgHeight);
                doc.save('charts-report.pdf');
            }
        })
        .catch((err) => {
            console.log(err)
        });
    }

What am I doing wrong? is there a way to fix it? (I can't change the version of the library) Or is there any better alternative? I tried even html-2-image but there seems to be other problems (like the download doesnt even start)

2
  • Do you know any good alternative which is completely working? Commented Sep 6, 2024 at 12:00
  • "I think there is a problem with box-shadows"—please be more specific. What did you expect to see, and what do you see instead? A minimal reproducible example would also help people understand what's happening. Commented Sep 5 at 13:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.