Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load PDF file in webview

I am having webview in my app, i am loading website in my webview and in that website there are multiple links of PDF file but while i am clicking on that it is not opening in webview, if i am checking it in my windows's browser it opening. i have enabled javascript but no luck, i used following properties also

webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.setWebViewClient(new myWebClient());
like image 385
Rajesh Panchal Avatar asked Jan 27 '26 13:01

Rajesh Panchal


2 Answers

Android does not work like iOS in this respect. The WebView widget cannot display PDF documents on Android.

You will have to:

  • Use a third party library (unfortunately, most open source pdf libs are GPL)

  • Open a pdf viewer app via an Intent

  • Use Google docs in a webview

like image 175
FD_ Avatar answered Jan 29 '26 03:01

FD_


this may help you,

String myPdfUrl = "http://example.com/awesome.pdf";
String url = "http://docs.google.com/gview?embedded=true&url=" + myPdfUrl;
Log.i(TAG, "Opening PDF: " + url);
webView.getSettings().setJavaScriptEnabled(true); 
webView.loadUrl(url);
like image 32
MdDroidd Avatar answered Jan 29 '26 03:01

MdDroidd