[英]html2canvas producing blurry image
I'm using html2canvas and jspdf to create pdfs from a html page.我正在使用 html2canvas 和 jspdf 从 html 页面创建 pdf。 But they produce a blurry image.
但它们会产生模糊的图像。
I already tried increasing scale and dpi, this didn't change much.我已经尝试增加比例和 dpi,这并没有太大变化。
Here is the code for converting the html to a picture:这是将html转换为图片的代码:
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:并用于创建 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();
I use 1.0.0-alpha.12 version.我使用 1.0.0-alpha.12 版本。 I use html2canvas download image, but this picture has a white transparent mask.
我使用 html2canvas 下载图片,但是这张图片有一个白色的透明蒙版。 Finally, I found if I set {backgroundColor: null} or other color, this problem disappear and picture is clear.
最后发现如果我设置了{backgroundColor: null}或者其他颜色,这个问题就消失了,图片清晰。
html2canvas(element, {
backgroundColor: '#1b2b4e'
}).then(canvas => {
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.