Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Not able to launch a pdf file in inappbrowser in android

I have a requirement to show a pdf in inappbrowser when user clicks on a link. It is working fine in ios but not working on android. I am using IBM worklight for my project. Below is the code I have used:

window.open("pdfURL","_blank","location=yes");

In ios the inappbrowser launches and displays the pdf but in android the inappbrowser is launches but no content is displayed

like image 808
user3878988 Avatar asked Oct 10 '14 17:10

user3878988


People also ask

Why PDF is not opening in Android?

Check the file format and ensure that you have installed an appropriate app to open the file. Download and install such an app from AppGallery or Google Play Store. For example, Microsoft Office or Adobe Acrobat needs to be installed to open PDF files.

Can we open PDF in WebView in Android?

We can load PDF in android easily using WebView. We will be using the simplest way for displaying PDF file in android. Using the Google Docs PDF viewer we could do this easily. Now lets get in to the implementation and source code.

How do I open a PDF in WebView?

Opening a PDF file in Android using WebView All you need to do is just put WebView in your layout and load the desired URL by using the webView. loadUrl() function. Now, run the application on your mobile phone and the PDF will be displayed on the screen.


1 Answers

Unlike iOS, which has a built-in PDF viewer - Android's webview does not have PDF viewer built-in.
This is why it is going to fail in Android.

You have 2 choices in Android:

  1. View the file using Google Docs by storing the file at a remote server and redirecting the user like so: window.open(encodeURI('https://docs.google.com/gview?embedded=true&url=http://www.your-server.com/files/your_file.pdf'), '_blank', 'location=yes,EnableViewPortScale=yes');

  2. Or use a Cordova plug-in. For example this one (you can search in Google for more). For this, you'll need to learn how to create Cordova plug-ins in Worklight.

You can read more options here: Phonegap InAppBrowser display pdf 2.7.0

like image 151
Idan Adar Avatar answered Sep 21 '22 18:09

Idan Adar