Do you know how to save and open a pdf using Capacitor and Ionic 4?

Hi @filippo-ots,

Yes, The code is in the link above. I am using it on a project at the moment so I will copy in here again.
Here is the link:

downloadPdf(pdfBase64: string) {
    const { Filesystem } = Plugins;

    if (this.plt.is('cordova')) {
        // Save the PDF to the device
        const fileName = 'timesheet.pdf';
        try {
          Filesystem.writeFile({
            path: fileName,
            data: pdfBase64,
            directory: FilesystemDirectory.Documents
            // encoding: FilesystemEncoding.UTF8
          }).then((writeFileResult) => {
            Filesystem.getUri({
                directory: FilesystemDirectory.Documents,
                path: fileName
            }).then((getUriResult) => {
                const path = getUriResult.uri;
                this.fileOpener.open(path, 'application/pdf')
                .then(() => console.log('File is opened'))
                .catch(error => console.log('Error openening file', error));
            }, (error) => {
                console.log(error);
            });
          });
        } catch (error) {
          console.error('Unable to write file', error);
        }
      } else {
      // On a browser simply use download
      this.pdfObj.download();
    }
  }
4 Likes