jsPDF在尝试实现时出现多个错误

jsPDF multiple errors when trying to implement

我有一个项目,我们正在合并 jsPDF 和 autotable,但我遇到了困难..

命令我 运行:

npm i jspdf --save  
npm install @types/jspdf --save
npm i jspdf jspdf-autotable --save

angular.json:

"scripts": ["../node_modules/jspdf/dist/jspdf.min.js",
              "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"]

ts 文件:

import * as jsPDF from 'jspdf';
import 'jspdf-autotable';


const doc = new jsPDF('portrait','px','a4');
    doc.autotable({
      head: [['Equipment_ID', 'Equipment_type_Description', 'Equipment_Description', 'Infrastructure_Name','Section_Name','Equipment_Condition','Equipment_Cost','Is_Active','Actions']],
      body: this.dataSource
    })

    doc.save("EquipmentList");


  }

错误

Property 'autotable' does not exist on type 'jsPDF'

当我这样声明时:

declare var jsPDF: any;

在我服务时,出现以下错误:

An unhandled exception occurred: Script file ../node_modules/jspdf/dist/jspdf.min.js does not exist.
See "C:\Users\reube\AppData\Local\Temp\ng-4iWKp5\angular-errors.log" for further details.

请尝试删除以下代码形式 angular.json:

"scripts": ["../node_modules/jspdf/dist/jspdf.min.js",
           "../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"]

要在 angular 5 中使用 jspdf-autotable,必须通过 npm

安装 jspdf 和 jspdf-autotable
    npm install jspdf --save
    npm install @types/jspdf --save-dev
    npm install jspdf-autotable --save

此外,将 jspdf 和 jspdf-autotable 文件添加到脚本数组中(angular-cli。json 或 angular.json)取决于您的 angular 版本

    "scripts": [
    "node_modules/jspdf/dist/jspdf.min.js",
    "node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
    ],

并且在组件中从不导入 jspdf 或 jspdf-autotable 只是。

忘记下面的导入。



    import * as jsPDF from 'jspdf'; 
    import 'jspdf-autotable';


只需在@Component之前使用:

    declare var jsPDF: any;