I am using pdf maker in my StencilJs app using the official Documentation at https://pdfmake.github.io/docs/0.1/getting-started/client-side/ First of all, I have installed it via npm using:
npm install pdfmake
Then I have created the following to test the functionality:
import * as pdfMake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
(<any>pdfMake).vfs = pdfFonts.pdfMake.vfs;
export class PDFCreateService {
constructor() {
// empty
}
public createNachrichtPDF(message: string): any {
const fileName: string = 'ba-postfach-' + moment(new Date()).format('DD-MM-YYYY');
const docDefinition = {
content: [message]
};
return pdfMake.createPdf(docDefinition);
}
}
This code does not work and in the class My-Messages where I instantiate this class, I keep on getting the following error:
index-2022e853.js:2706 TypeError: Cannot read properties of undefined
(reading 'pdfMake') at my-messages.entry.js:78239 undefined
Uncaught (in promise) Error: Constructor for "my-messages#undefined" was
not found at initializeComponent
How can I solve this error?