【问题标题】:How to get the file size of a generated pdf (in bytes) angular using jspdf and html2canvas如何使用 jspdf 和 html2canvas 获取生成的 pdf 的文件大小(以字节为单位)
【发布时间】: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


    【解决方案1】:

    使用 blob 输出它,像这样。

      let blob = pdf.output("blob");
      console.log(blob.size);
      pdf.save("file.pdf"); // Generated PDF
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-05
      • 1970-01-01
      • 2012-02-17
      • 2017-05-27
      • 2013-02-01
      • 2019-04-06
      • 1970-01-01
      相关资源
      最近更新 更多