Jspdf-autotable: Angular 2 Error doc.autoTable is not a function

Created on 11 Apr 2017  ·  9Comments  ·  Source: simonbengtsson/jsPDF-AutoTable

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. (view.js:664)
at HTMLButtonElement. (dom_renderer.js:489)
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)

Uploading Capture d’écran 2017-04-11 à 18.04.51.jpg…

Most helpful comment

this code solve my issue.
import * as jsPDF from 'jspdf'; import { autoTable } from 'jspdf-autotable'; import 'jspdf-autotable';

All 9 comments

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');

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tapz picture tapz  ·  3Comments

JoakFlores picture JoakFlores  ·  3Comments

sciefylab picture sciefylab  ·  6Comments

webdream-fr picture webdream-fr  ·  6Comments

simonbengtsson picture simonbengtsson  ·  5Comments