Issue with Generating PDF Using Angular 8, JSPDF, and JSPDF-AutoTable
I am facing a challenge with exporting/generating a PDF based on an HTML grid. I need to make some DOM changes with CSS, remove toggle buttons, alter the header, etc. However, all the solutions I have tried so far either have printing glitches or do not support autoTable functionality like pdfmake-wrapper and ngx-export-as. The last solution I attempted involved using Renderer2 for DOM manipulation, but it does not meet my requirement of seamless CSS class changes without any flickering. Hence, I am reverting back to JSPDF.
To address this issue, I have installed jspdf and jspdf-autotable packages via npm.
"dependencies": {
...
"jspdf": "^1.5.3",
"jspdf-autotable": "^3.2.4",
...
}
In the angular-cli.json file, I have included the necessary scripts:
"scripts": [
"../node_modules/jspdf/dist/jspdf.min.js",
"../node_modules/jspdf-autotable/dist/jspdf.plugin.autotable.js"
],
In my component.ts file, I have imported these files as follows:
import * as jsPDF from 'jspdf';
import * as autoTable from 'jspdf-autotable';
I have also experimented with different ways to import jspdf-autotable.
import * as jsPDF from 'jspdf';
import 'jspdf-autotable';
Furthermore, I have tried another combination.
import jsPDF = require('jspdf');
import { autoTable as AutoTable } from 'jspdf-autotable';
However, none of these approaches seem to be effective.
// In My component.ts file I'm using sample code as follows:
let columns = ["ID", "Name", "Age", "City"];
var data = [
[1, "Jonatan", 25, "Gothenburg"],
[2, "Simon", 23, "Gothenburg"],
[3, "Hanna", 21, "Stockholm"]
];
const doc = new jsPDF(); // or let doc = new jsPDF.default();
doc.autoTable(columns, data);
doc.save("filename");
During debugging, I encounter the following errors when running the node command to start the app:
a - Property 'autoTable' does not exist on type 'jsPDF'.
b - Error TS2339: Property 'default' does not exist on type 'typeof jsPDF'.
Any helpful insights or suggestions?