IPhone : Download PDF file locally in hybrid App

on Wednesday, February 25, 2015

I am developing a hybrid app. One of the requirements is to download the PDF from a service which is returning filea as Base64 encoded string. My below code is working in browser but didn't work in android/iphone app.



downloadStatements = function(){
// Convert the Base64 string back to text.
var byteString = atob(encodedData);

// Convert that text into a byte array.
var ab = new ArrayBuffer(byteString.length);
var ia = new Uint8Array(ab);
for (var i = 0; i < byteString.length; i++) {
ia[i] = byteString.charCodeAt(i);
}

// Blob for saving.
var blob = new Blob([ia], { type: "application/pdf" });
var a = document.createElement('a');
a.href = window.URL.createObjectURL(blob);
a.download = "test.pdf";
a.click();
// Tell the browser to save as report.pdf.
//saveAs(blob, "report.pdf");
};


Hybrid or mobile app development is new for me, so I may be making some fundamental mistake. I's using angular but that itself is new to me. ;)


0 comments:

Post a Comment