jsPDF AutoTable-autoTable不是功能 [英] jsPDF AutoTable - autoTable is not a function

查看:174
本文介绍了jsPDF AutoTable-autoTable不是功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Angular应用上使用JSPdf,并且尝试使用JS autotable插件,但遇到JS错误

I'm using JSPdf on an Angular app, and I'm attempting to use the JS autotable plugin but I'm running into the JS error

例外:未捕获(承诺中):TypeError:doc.autoTable不是函数

EXCEPTION: Uncaught (in promise): TypeError: doc.autoTable is not a function

TypeError:doc.autoTable不是函数

TypeError: doc.autoTable is not a function

我通过npm安装了jspdf和jspdf-autotable,我确认它们在节点模块中.

I have jspdf and jspdf-autotable installed via npm, I confirmed they are in the node modules.

我以这种方式导入了两个插件:

I've imported both plugins this way:

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

这是我的代码:

private renderPdf():void{
    let testcolumns = ["TestCol1", "TestCol2"];
    let testrows = [["test item 1", "test item 2"]];
    let doc = new jsPDF();
    doc.autoTable(testcolumns, testrows);
    doc.save('sample.pdf');
}

这里是否有任何我想念的东西,或者我可以提供更多代码来帮助确定问题?

Is there anything I could be missing here or more code I could provide to help determine the issue?

谢谢!

推荐答案

只需删除导入的第一行的第二行并添加以下行:

Just delete the 2 first line of imports and add the following lines:

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

您可以在此处看到示例

这篇关于jsPDF AutoTable-autoTable不是功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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