I'm trying to save the pdf file of this example:
http://gonehybrid.com/how-to-create-and-display-a-pdf-file-in-your-ionic-app/
to my localData. I found i will need file plugin, but i don't know how to save the blob file to my system. I tried this two:
$cordovaFile.writeFile(cordova.file.externalCacheDirectory, "file.pdf", pdf, true)
.then(function(success) {
console.log("file creato")
}, function(error) {
console.log("errore creazione file")
});
or
$cordovaFile.createFile(cordova.file.dataDirectory, $scope.pdfUrl, true)
.then(function (success) {
// success
}, function (error) {
// error
});
but i can't storage it. How can i do that?
My solution:
var pathFile = "";
var fileName = "report.pdf";
var contentFile = blob;
if (ionic.Platform.isIOS()) {
pathFile = cordova.file.documentsDirectory
} else {
pathFile = cordova.file.externalDataDirectory
}
$cordovaFile.writeFile(pathFile, fileName, contentFile, true)
.then(function(success) {
//success
}, function(error) {
alert("error in the report creation")
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With