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
EXCEPTION: Uncaught (in promise): TypeError: doc.autoTable is not a function
TypeError: doc.autoTable is not a function
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'
and here is my code:
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?
Thanks!
Just delete the 2 first line of imports and add the following lines:
var jsPDF = require('jspdf');
require('jspdf-autotable');
You can see an example here
i was geting same issue and I fixed it like this:
import jsPDF from '../../node_modules/jspdf/dist/jspdf.umd.min.js'
import { applyPlugin } from 'jspdf-autotable'
applyPlugin(jsPDF)
i use "jspdf": "^2.3.1", "jspdf-autotable": "^3.5.20" i hope it helps you!
I was getting same issue and This one is worked for me. i have written it in import as
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';
And in function i declared it as
const doc = new jsPDF();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With