1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

pdfMake 0.2.20 ERROR TypeError: Cannot read properties of undefined (reading 'length') for...

Discussão em 'Angular' iniciado por hemant, Setembro 4, 2025.

  1. hemant

    hemant Guest

    environment: Angular 17, pdfMake 0.2.20

    This was a working code with pdfMake version 0.2.14

    the error states that Cannot read properties of undefined (reading 'length'). From the service code lines the .length refers to node.table.body.length for table layout of docDefinition, which is not really a problem. I commented those lines just to be sure, and this error still exists. Not able to figure out where is the issue.

    ERROR:

    pdf.service.ts:40
    ERROR TypeError: Cannot read properties of undefined (reading 'length')
    at __webpack_modules__.98883.DocPreprocessor.preprocessTable (pdfmake.js:74310:42)
    at __webpack_modules__.98883.DocPreprocessor.preprocessNode (pdfmake.js:74257:15)
    at __webpack_modules__.98883.DocPreprocessor.preprocessVerticalContainer (pdfmake.js:74291:19)
    at __webpack_modules__.98883.DocPreprocessor.preprocessNode (pdfmake.js:74251:15)
    at __webpack_modules__.98883.DocPreprocessor.preprocessDocument (pdfmake.js:74229:14)
    at __webpack_modules__.65300.LayoutBuilder.tryLayoutDocument (pdfmake.js:50906:39)
    at __webpack_modules__.65300.LayoutBuilder.layoutDocument (pdfmake.js:50897:21)
    at __webpack_modules__.81566.PdfPrinter.createPdfKitDocument (pdfmake.js:59478:22)
    at pdfmake.js:38314:21
    at _ZoneDelegate.invoke (zone.js:369:28)


    component.ts

    onPreviewPdf(){
    if(!this.doc) return;
    if(!this.client) return;

    const fileName = this.modelName.toUpperCase() + '-' + this.doc.docNumber + '-' + this.doc.compName;
    const isTaxDoc = false;
    this.pdfService.generateDownloadQuotePiPdf(this.customer, this.doc, fileName);

    }


    pdf.service.ts

    async loadPdfMaker() {
    if(!this.pdfMake) {
    const pdfMakeModule = await import('pdfmake/build/pdfmake');
    const pdfFontsModule = await import('pdfmake/build/vfs_fonts'); // line 40, where the error is pointing to
    this.pdfMake = pdfMakeModule.default;
    // this.pdfMake.vfs = pdfFontsModule.default.pdfMake.vfs; // working code line for 0.2.14

    /// new lines added for pdfMake 0.2.20
    (<any>this.pdfMake).addVirtualFileSystem(pdfFontsModule);
    this.pdfMake.vfs = pdfFontsModule.default.vfs;
    }
    }

    async generateDownloadQuotePiPdf(cust: Customer, doc: QuotePi, fileName: string) {
    await this.prepareQuotePiPdf(cust, doc);
    /// some lines in this method has .length, which were commented, as I am sure these are not an issue.

    await this.loadPdfMaker();
    this.pdfMake.createPdf(this.docDef).download(fileName);
    }

    Continue reading...

Compartilhe esta Página