首页 > 解决方案 > doc.addImage 不是 Angular 6 中使用的 jspdf 中的函数错误

问题描述

我在角度 6 中使用最新版本的 jsPDF (1.5.2)

源代码

public captureScreen()  
{  
    var data = document.getElementById('contentToConvert'); 
    html2canvas(data).then(canvas => { 
    // Few necessary setting options 
    var imgWidth = 208; 
    var pageHeight = 295; 
    var imgHeight = canvas.height * imgWidth / canvas.width; 
    var heightLeft = imgHeight; 

    const contentDataURL = canvas.toDataURL('image/png');
    let doc = new jsPDF('p', 'mm', 'a4'); // A4 size page of PDF 
    var position = 0; 
   // pdf.text("Octonyan loves jsPDF", 35, 25);
    doc.addImage(contentDataURL, 'PNG', 0, position, imgWidth, imgHeight) ;
    doc.save('MYPdf.pdf'); // Generated PDF  
    }); 

} 

在 node_modules jspdf > dist 文件夹中包含这些文件

在此处输入图像描述

错误信息

core.js:1673 ERROR Error: Uncaught (in promise): TypeError: doc.addImage is not a function TypeError: doc.addImage is not a function
at movielists.component.ts:301

标签: htmlpdfangular6

解决方案


今天 1.5.3 版发布并修复了这些问题。


推荐阅读