Ionic PDFMake throws error when swtiching between pages after PDF generation

Viewed 145

I am using PDFMake, library to generate PDF from my ionic/angular application. The PDF generation is working perfectly fine. However issue is that -

  1. After pdf generation process is completed, I go back to dashboard page
  2. And from dashboard page I go to Another page (any page, same pdf generation page or any other page), I get following error.

enter image description here

I have following codes:

import pdfMake from 'pdfmake/build/pdfmake';
import pdfFonts from 'pdfmake/build/vfs_fonts';
pdfMake.vfs = pdfFonts.pdfMake.vfs;

//---------------------
//---------------------

ionViewWillLeave(){
    if(this.pdfObj) this.pdfObj = null;
}

generatePdf(){
    let docDefinition = {
      pageSize: "A3",
      content: [
        ..............
      ],
    }

    this.pdfObj = pdfMake.createPdf(docDefinition);
    this.pdfObj.download();
}
  ------------------------------------

Any help will be highly appreciated.

Thanks

1 Answers

This issue is due to pdfmake.js polyfills all promises related function and due to this all ionic promises are redirecting to those polyfiled functions

currently I'm also facing same issue for iOS devices only so I have added workaround as follows which may help you as well (Not sure with exact solution)

ionic 5 cordova 10 pdfmake 0.2.4

enter image description here

Related