In an Angular app generated by JHipster, I managed to produce PDFs via jsPDF in dev mode. But when I build it and push it on a VPS, adding images in the doc crashes the webApp.
717.1183bdcffdb5d922.js:1 ERROR TypeError: Cannot read properties of undefined (reading 'data')
at i.__addimage__.getImageFileTypeByImageData (641.074d6c566f08a36e.js:1:287740)
at Object.Zt (641.074d6c566f08a36e.js:1:295400)
at i.addImage (641.074d6c566f08a36e.js:1:295162)
at m.addImageEntete (287.1ee6c0684b572bd4.js:1:800)
at M.getPDF (641.074d6c566f08a36e.js:1:47054)
at M.generatePDFComplet (641.074d6c566f08a36e.js:1:115186)
at 641.074d6c566f08a36e.js:1:139516
at d7 (717.1183bdcffdb5d922.js:1:217724)
at c (717.1183bdcffdb5d922.js:1:217891)
at HTMLButtonElement.<anonymous> (717.1183bdcffdb5d922.js:1:330709)
I can display them in the address bar whith their URL though.
Here is a bit of relevant code :
import { jsPDF, jsPDFOptions } from 'jspdf';
import autoTable, { RowInput } from 'jspdf-autotable';
export const ENTETE_PATH_ABMS = '/content/images/prints/abms_entete.jpg';
@Injectable({
providedIn: 'root',
})
export class PrintService {
constructor() {}
getPDF() {
const options: jsPDFOptions = {
orientation: 'p',
unit: 'mm',
format: 'a4',
putOnlyUsedFonts: true,
floatPrecision: 16, // or "smart", default is 16
};
const doc = new jsPDF(options);
doc.addImage(ENTETE_PATH_ABMS, 'jpg', posX, posY, w, h);
}
}