Hello.
I'm trying to use on Ionic 2 and WebStrom.
You are showing me the following error when compiling:
autoTable does not exist on type jsPDF
me code is like this:
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';
dowloadPDF() {
let doc = new jsPDF('p', 'pt');
let columns = [
{title: "ID", dataKey: "id"},
{title: "Name", dataKey: "name"},
{title: "Country", dataKey: "country"},
];
let rows = [
{"id": 1, "name": "Shaw", "country": "Tanzania"},
{"id": 2, "name": "Nelson", "country": "Kazakhstan"},
{"id": 3, "name": "Garcia", "country": "Madagascar"},
];
// Error ========================
doc.autoTable(columns, rows);
doc.save('teste.pdf');
}
Try change the import :
import jsPDF from 'jspdf';
import autoTable from 'jspdf-autotable';
dowloadPDF() {
let doc = new jsPDF('p', 'pt');
let columns = [
{title: "ID", dataKey: "id"},
{title: "Name", dataKey: "name"},
{title: "Country", dataKey: "country"},
];
let rows = [
{"id": 1, "name": "Shaw", "country": "Tanzania"},
{"id": 2, "name": "Nelson", "country": "Kazakhstan"},
{"id": 3, "name": "Garcia", "country": "Madagascar"},
];
// Error ========================
doc.autoTable(columns, rows);
doc.save('teste.pdf');
}
It's working for me in vue.js
Hello.
I'm sorry it did not work as you showed it.
Look at the error
doc.autoTable is not a function
Typescript Error
Property 'autoTable' does not exist on type 'jsPDF'.
https://jsfiddle.net/fbf0wLe5/
Exclude line 2 (import js-autotable) Do you have the same error
I already did this, it even works, but it gives an error in the compilation of Typescript
i have the same issue in angular 2
issue in plugin jspdf-autotable/src/main.ts
it shows lot of errors
Did you add
"../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
to angular-cli.json ?? The same issue was for me and resolved instantly after adding these lines in scripts array of angular-cli.json file. Hope this helps for new comers too.
I solved this issue, first import the Jspdf import * as jsPDF from 'jspdf';
i'm used a codesmells tatic, copied the content of jspdf autotable and pasted inside
the jspdf.js, then works fine for me.
Try solution posted here if using angular #375
@simonbengtsson any plan to add type definition to @types/jspdf ?? then any project involving typescript could pass the type checking.
/// file: node_modules\@types\jspdf\index.d.ts
// jsPDF plugin: AutoTable
autoTable(options:any):jsPDF;
OR, there's a workround, add // @ts-ignore before jsPDF.autoTable
// @ts-ignore
doc.autoTable()
This was the solution for me (Angular 2): https://stackoverflow.com/a/54332585/12410011
exportPdf() {
this.exportColumns = this.selectedCols.map(col => ({title: col.header, dataKey: col.field}));
import("jspdf").then(jsPDF => {
import("jspdf-autotable").then(x => {
//@ts-ignore
const doc = new jsPDF.default('p','mm');
//@ts-ignore
doc.autoTable(this.exportColumns, this.exportData);
doc.save('tests.pdf');
})
})
}
Most helpful comment
@simonbengtsson any plan to add type definition to @types/jspdf ?? then any project involving typescript could pass the type checking.
OR, there's a workround, add // @ts-ignore before jsPDF.autoTable