jsPDF中找不到autotable

时间:2018-07-25 15:12:33

标签: jspdf-autotable

此后,我也遇到了同样的问题。 1.用以下命令安装jsPDF和jspdf-autotable    npm安装jspdf    npm install --save @ types / jspdf    npm install jspdf-autotable --save

  1. 使用以下命令将jspdf导入app.component.ts   从``jspdf''导入*作为jsPDF;   导入'jspdf-autotable';
  2. 这是我的方法。ts

generatedile(){
          var columns = [
            {title: "ID", dataKey: "id"},
            {title: "Name", dataKey: "name"}, 
            {title: "Country", dataKey: "country"},
        ];
        var rows = [
            {"id": 1, "name": "Shaw", "country": "Tanzania"},
            {"id": 2, "name": "Nelson", "country": "Kazakhstan"},
            {"id": 3, "name": "Garcia", "country": "Madagascar"},
        ];
         
        // Only pt supported (not mm or in)
        var doc = new jsPDF('p', 'pt');
        doc.autoTable(columns, rows, {
            styles: {fillColor: [100, 255, 255]},
            columnStyles: {
              id: {fillColor: 255}
            },
            margin: {top: 60},
            addPageContent: function(data) {
              doc.text("Header", 40, 30);
            }
        });
        doc.save('table.pdf');
}

1 个答案:

答案 0 :(得分:0)

您不应导入jspdf-autotable。试试这个

var jsPDF = require('jspdf');
require('jspdf-autotable');