@karvanj
install File and File Opener plugin.
File plugin
ionic cordova plugin add cordova-plugin-file
npm install --save @ionic-native/file
File Opener plugin:
cordova plugin add cordova-plugin-file-opener2
npm install --save @ionic-native/file-opener
import { FileOpener } from '@ionic-native/file-opener’;
import { File } from ‘@ionic-native/file’;
constructor(private file: File, private fileOpener: FileOpener){
}
downloadBlobToPDF(){
let downloadPDF: any = ‘W0JFR0lOXQolUERGLTEuMgp6R1/V+d9KpBi3sCNzNh…….’
fetch('data:application/pdf;base64,' + downloadPDF,
{
method: "GET"
}).then(res => res.blob()).then(blob => {
this.file.writeFile(this.file.externalApplicationStorageDirectory, 'statement.pdf', blob, { replace: true }).then(res => {
this.fileOpener.open(
res.toInternalURL(),
'application/pdf'
).then((res) => {
}).catch(err => {
console.log(‘open error’)
});
}).catch(err => {
console.log(‘save error’)
});
}).catch(err => {
console.log(‘error’)
});
}
and add following lines in config.xml
<preference name="AndroidPersistentFileLocation" value="Compatibility" />
<preference name="AndroidExtraFilesystems" value="sdcard,cache" />