I use the jsPDF version 1.5.3 (jspfd.min.js downloaded and saved) and it works fine for every years. Yet i have tested the version 2.5.1 (jspfd.min.js downloaded and saved from unpkg). This gives the error: Uncaught ReferenceError: jsPDF is not defined
. This is not possible because the variable/function is definitely present. With version 1.5.3 this error should otherwise also appear, but this is not the case. When (with 2.5.1) i call in the Firefox console the variable jsPDF
it changes automatically to jspdf
and display an object. Call really jsPDF
it ist the error. When i change the name in my script from new jsPDF
to new jspdf
it gives the error: Uncaught TypeError: jspdf is not a constructor
. What is the problem?
Apparently there are some breaking changes in version 2.0.0.
We also changed the name of the global variable to jspdf (lower case) when using script tags to be consistent with the new es modules format and named imports/exports.
Adding the following line should work for backward compatibility:
window.jsPDF = window.jspdf.jsPDF
You need to import the module as follows:
import { jsPDF } from "jspdf";
For other module formats, take a look at the repo doc directly: https://github.com/parallax/jsPDF, ex.:
// Node.js
const { jsPDF } = require("jspdf");
// Globals
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
// ...