In Android, unable to load pdf when we are assiging a base64 string to a browser widget

This thread was migrated from an old forum. It may contain information that are no longer valid. For further assistance, please post a new question or open a support ticket from the Customer Support portal.

#[Informational Post]​

Below are the browser limitations for various platforms. Please find them below.

1. Desktop web browser(google/Safari): The desktop web browsers will understand the content returned by the server based on the Content-Type like PDF or CSV. They will open the content in a seperate browser window.

2. Android web browser(google): The Android web browser won't have the capability to open the file contents in a seperate browser window or same browser window. Hence they will prompt us the option to download the file if the server is directly returning the file. If the server is not returning the file directly and if it is returning the content like base 64 then it is our responsibility to create the download document object as shown in the below snippet.

CommonUtilities.hideProgressBar(this.view);

var docbufferVal = "data:application/pdf;base64," + url;

kony.print(" Final Value : : " + docbufferVal);

var blobObj = this.dataURLtoBlob(docbufferVal);

var temp_url = window.URL.createObjectURL(blobObj);

var title = "Statements";

var userAgent=navigator.userAgent;

if ((userAgent.match(/Android/i)) || (userAgent.match(/iPhone/i))) {

var a = document.createElement("a");

document.body.appendChild(a);

a.style = "display: none";

a.href = temp_url;

a.download = "Statements.pdf";

a.click();

In both the above cases we are actually downloading the files and if we click on this file it will be opened in the native PDF applications or text applications. But if you want to see the content in browser window directly then you have to use the google docs integration as mentioned in the below doc.

https://stackoverflow.com/questions/7437602/how-to-display-a-pdf-via-android-web-browser-without-downloading-first

3. IOS web browser(safari): The safari browser will open the files in the window directly as it has that capability. But as you want the file to be opened in a seperate in window it is our responsibility to do that. You have to create the new window object and have to put your entire javascript service code in the script as shown below

var script1 = document.createElement('script');

var xhttp = new XMLHttpRequest();

script1.innerHTML =xhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

var content_type=xhttp.getResponseHeader("content-type");

var ext=content_type.indexOf("csv")>=0 ? ".csv" : ".qfx";

download(xhttp.responseText, "AccountStatment"+ext, content_type);

CommonUtilities.hideProgressBar(scopeObj.view);

} else if(this.readyState == 4){

CommonUtilities.hideProgressBar(scopeObj.view);

}

};

xhttp.open("GET",mfURL+prefix+suffix, true);

xhttp.send();

window.document.getElementsByTagName('head')[0].appendChild(script1);

The above are the cases that we need to look into.

Thanks and Regards,

Thank you @Connow Cvmpxell​ for sharing this helpful information with the community! 👍

This is not working for android . Also can you provide you dataURLtoBlob function