@wekas wrote:
I am generating a pdf using pdfMake and writing it to an android device so that I can open it.
I am using Capacitor and the file system command does not appear to take a blob (this worked in cordova) so I am sending it a base64.
It seems to write ok but when I open the pdf it says the format is invalid.Note: The cordova file plugin does not work with Capacitor (Cordova plugins not working with Capacitor) so it seems I am stuck with Capacitor file system commands.
Can I write to blob in capacitor or is there a problem with my code??
Help please, I have spend days on this!
this.pdfObj = pdfMake.createPdf(docDefinition); if (this.plt.is('cordova')) { this.pdfObj.getBase64((data) => { this.pdfBase64 = data; console.log(this.pdfBase64); }); } } downloadPdf() { const { Filesystem } = Plugins; if (this.plt.is('cordova')) { console.log('3'); // Save the PDF to the data Directory of our App const fileName = 'defectreport.pdf'; try { Filesystem.writeFile({ path: fileName, data: this.pdfBase64, directory: FilesystemDirectory.Data, encoding: FilesystemEncoding.UTF8 }).then((writeFileResult) => { console.log('File Written'); Filesystem.getUri({ directory: FilesystemDirectory.Data, path: fileName }).then((getUriResult) => { console.log(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); }); }); console.log('writeFile complete'); } catch (error) { console.error('Unable to write file', error); }
Posts: 1
Participants: 1