【发布时间】:2020-02-03 09:53:25
【问题描述】:
我目前正在使用 html2canvas 和 jspdf 将 html 页面转换为 PDF。 我想以字节为单位检索文件大小,以便在用户的屏幕上显示它。如果有人知道一个方便的方法,那将很有帮助。感谢您的帮助:)
这里是将html转换为PDF的代码:
exportPDF() {
const data = document.getElementById("content");
html2canvas(data).then(canvas => {
// Few necessary setting options
const imgWidth = 208;
const imgHeight = (canvas.height * imgWidth) / canvas.width;
const contentDataURL = canvas.toDataURL("image/png");
const pdf = new jsPDF("p", "mm", "a4"); // A4 size page of PDF
const position = 0;
pdf.addImage(contentDataURL, "PNG", 0, position, imgWidth, imgHeight);
pdf.save("file.pdf"); // Generated PDF
});
}
【问题讨论】:
标签: angular jspdf html2canvas