【问题标题】:Can't add canvas from html2canvas to jspdf addHTML() method无法将 html2canvas 中的画布添加到 jspdf addHTML() 方法
【发布时间】:2018-05-02 16:21:18
【问题描述】:

我在 angular5 之上构建应用程序,并尝试使用 jspdf.addHTML() 结合 html2canvas 的函数添加 html。

const content = this.vc_print_section.nativeElement;

html2canvas(content).then(canvas => {
   const doc = new jsPDF('p', 'mm');

   doc.addHTML(canvas, _ => {
      doc.save('test.pdf');
   });
});

但是发生了错误:

ERROR Error: Uncaught (in promise): [object String]

【问题讨论】:

    标签: angular jspdf html2canvas


    【解决方案1】:

    jsPDF 在 addHTML 方法中自己调用 html2canvas。正确的代码应该是这个:

    const content = this.vc_print_section.nativeElement;
    const doc = new jsPDF('p', 'mm');
    
    doc.addHTML(canvas, _ => {
        doc.save('test.pdf');
    });
    

    即使这样,如果您使用的是html2canvas的最新版本,我认为它与jsPDF不兼容。它可能需要在 addhtml.js 插件中进行一些更改。

    【讨论】:

      猜你喜欢
      • 2014-11-12
      • 1970-01-01
      • 2019-06-05
      • 1970-01-01
      • 2016-06-28
      • 2014-12-02
      • 1970-01-01
      • 1970-01-01
      • 2018-11-11
      相关资源
      最近更新 更多