我目前正在使用html2canvas将一个div的内容转换为png格式,但是使用scale: 5或dpi:等参数对生成的图片质量没有任何影响。
这是html2canvas的结果,因为我在pdfcon()函数中添加canvas,它非常模糊 :)
我已经在互联网上搜寻了答案,但毫无所获,希望能得到帮助 :)(我还在使用Quill编辑器)
HTML:
<div id="editorOne" class="pdf-convert ql-container ql-snow">
<div id="specialEdit" class="ql-editor" data-gramm="false" contenteditable="false">
<?php echo stripslashes($newClean); ?>
</div>
</div>
<button onclick="pdfcon()">Save Pdf</button>
JS:
function pdfcon() {
html2canvas($("#editorOne"), {
scale: 5,
onrendered: function (canvas) {
document.body.appendChild(canvas);
var img = canvas.toDataURL("png");
var doc = new jsPDF("p", "mm", "a4");
var width = doc.internal.pageSize.getWidth();
var height = doc.internal.pageSize.getHeight();
doc.addImage(img, 'PNG', 0, 0, width, height);
doc.save('testing.pdf');
}
})
};