I have used jsPDF-AutoTable in my project Angular 2 but when I run the code i found error to call AutoTable.
I follow all the instruction in Redmine to configure jsPDF with my project.
Version angular :2.4.8
code:
let jsPDF = require('jspdf');
let doc = new jsPDF('p', 'pt');
var columns = ["ID", "Name", "Country"];
var rows = [
[1, "Shaw", "Tanzania"],
[2, "Nelson", "Kazakhstan"],
[3, "Garcia", "Madagascar"] ];
doc.autoTable(columns, rows);
doc.save("table.pdf");
Result:
ypeError: doc.autoTable is not a function
at GestionUtilisateursComponent.webpackJsonp.443.exports.GestionUtilisateursComponent.GestionUtilisateursComponent.downloadPDF (gestion-utilisateurs.component.ts:342)
at CompiledTemplate.proxyViewClass.View_GestionUtilisateursComponent0.handleEvent_28 (/AppModule/GestionUtilisateursComponent/component.ngfactory.js:3176)
at CompiledTemplate.proxyViewClass.
at HTMLButtonElement.
at ZoneDelegate.invokeTask (zone.js:398)
at Object.onInvokeTask (ng_zone.js:264)
at ZoneDelegate.invokeTask (zone.js:397)
at Zone.runTask (zone.js:165)
at HTMLButtonElement.ZoneTask.invoke (zone.js:460)
Are you importing jspdf-autotable? Should look something like this:
let jsPDF = require('jspdf');
require('jspdf-autotable');
let jsPDF = require('jspdf');
require('jspdf-autotable'); is again throwing error Cannot find name 'require'.
Any help is appreciated. Thanks.
@rakhtar92 got the same problem. did you fix it?
Still not working.
this code solve my issue.
import * as jsPDF from 'jspdf';
import { autoTable } from 'jspdf-autotable';
import 'jspdf-autotable';
None of the mentioned solutions seem to work for me.
thanks @chandanakgd !!
To avoid TS error 'autoTable' is not a function:
import * as jsPDF from 'jspdf';
require('jspdf-autotable');
...
let doc: any = new jsPDF();
doc.autoTable(colums, rows);
thanks @chandanakgd it worked for me
i have used it in import as
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';
And in function i declared it as
const doc = new jsPDF('landscape', 'pt', 'a4');
Most helpful comment
this code solve my issue.
import * as jsPDF from 'jspdf'; import { autoTable } from 'jspdf-autotable'; import 'jspdf-autotable';