【发布时间】:2019-11-27 10:00:36
【问题描述】:
我目前正在通过 html2canvas 将 div 的内容转换为 png,但是使用 scale: 5 或 dpi: 等对随后的图像质量没有任何影响。 这是 html2canvas 的结果,因为我在 pdfcon() 函数期间附加了画布,并且它非常模糊:)。 我已经在互联网上搜寻无济于事的答案,任何帮助将不胜感激:)。 (我也在用 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');
}
})
};
【问题讨论】:
标签: javascript html pdf-generation html2canvas html2pdf