jsPDF类型不存在属性"autoTable" [英] Property 'autoTable' does not exist on type jsPDF

查看:613
本文介绍了jsPDF类型不存在属性"autoTable"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular2Node JS.我已经安装了 jspdf

I am using angular2 and Node JS. I have installed jspdf and jspdf-autotable both modules using npm. In angular-cli.json file, I have embedded the scripts:

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

在我的component.ts文件中,我已按以下方式导入了这些文件:

In my component.ts file , I have imported these files as follows:

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

我也尝试过这些行来导入jspdf-autotable

I have also tried these lines to import jspdf-autotable

import { autoTable } from 'jspdf-autotable'; 
import 'jspdf-autotable';

但是没有任何作用.

component.ts文件的功能中,我使用的示例代码如下:

In function of component.ts file I am using sample code as follows:

var columns = ["ID", "Country", "Rank", "Capital"];
        var data = [
            [1, "Denmark", 7.526, "Copenhagen"],
            [2, "Switzerland",  7.509, "Bern"],
            [3, "Iceland", 7.501, "Reykjavík"],
            [4, "Norway", 7.498, "Oslo"],
            [5, "Finland", 7.413, "Helsinki"]
        ];
        var doc = new jsPDF();
        doc.autoTable(columns, data);
        doc.output("dataurlnewwindow");

但是现在当我运行node命令以启动应用程序时,然后在编译过程中出现以下错误:

But now when I run the node command to start app then during compilation I am getting error as:

类型'jsPDF'不存在属性'autoTable'.

Property 'autoTable' does not exist on type 'jsPDF'.

有人可以建议吗?

推荐答案

我得到了答案:

无需在component.ts文件中导入jspdf或jspdf-autotable.

No need to import jspdf or jspdf-autotable in component.ts file.

component.ts:

component.ts:

import { Component, Input, OnInit, Inject } from '@angular/core';
declare let jsPDF;

就我而言

var doc = new jsPDF('l', 'mm', [305, 250]);

var options1 = {
   padding: 50
};

doc.addHTML($('#riskdate_heading'),0,10,options1 ,() => {

   doc.addHTML($('#risktitle'),0,30,options1, () => {

     var res = doc.autoTableHtmlToJson(document.getElementById("riskTable"));

                var header = function(data) {
                    doc.setFontSize(18);
                    doc.setTextColor(40);
                    doc.setFontStyle('normal');
                };

                var riskoptions = {
                                    tableWidth: 'auto',
                                    addPageContent: header,
                                    margin: {  top: 10, horizontal: 7 },
                                    startY:  50,
                                    columnStyles: {0: {columnWidth: 'wrap'}}
                                };

                doc.autoTable(res.columns, res.data, riskoptions);

                doc.save("table.pdf");
        });
    });

这篇关于jsPDF类型不存在属性"autoTable"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆