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)
1