html2canvas官网blurry,javascript - html2canvas producing blurry image - Stack Overflow

博主在尝试使用html2canvas和jspdf将HTML页面转换为PDF时遇到了图像模糊的问题。尽管尝试通过增加比例和DPI来改善图像质量,但效果不明显。代码示例显示了html2canvas用于将HTML转化为图片,然后jsPDF用于创建PDF,但图像质量仍然不佳。
摘要由CSDN通过智能技术生成

I'm using html2canvas and jspdf to create pdfs from a html page. But they produce a blurry image.

I already tried increasing scale and dpi, this didn't change much.

Here is the code for converting the html to a picture:

html2canvas(document.body, {

// Scale image for better quality

scale: 5,

dpi: 300,

onrendered: function (canvas) {

// Convert image to dataURL

const image = canvas.toDataURL("image/png");

// Save dataURL in session storage

try {

window.sessionStorage.setObject(new Date().getTime(), image);

document.getElementById('status').innerHTML = "Aktuelle Kennzahl erfolgreich hinzugefügt!"

} catch (error) {

console.log(error);

document.getElementById('status').innerHTML = "Fehler beim Hinzufügen der Kennzahl!"

}

}

});

And for creating the pdf:

let doc = new jsPDF('p', 'mm', 'a4');

// Set image width to a4

const width = doc.internal.pageSize.getWidth();

const height = doc.internal.pageSize.getHeight();

doc.addImage(image, 'PNG', 0, 0, width, height * 0.65, '', 'SLOW');

doc.addPage();

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值