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