Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to open PDF documents in WebView

I am using WebView to open a url which is in fact a pdf document. Here is the code snippet.

WebView webView = (WebView) context.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.loadUrl("http://www.stagecoachbus.com/PdfUploads/Timetable_28768_5.pdf");

And the error obtained is:

EventHub.removeMessages(int what = 107) is not supported before the WebViewCore is set up

I was able to open normal web pages. However, opening pdf files results in exception.

Any thoughts?

Thanks in advance!

like image 362
Renjith Avatar asked Dec 06 '25 04:12

Renjith


1 Answers

To open pdf in Webview , it better to show pdf via google doc service

WebView webView = (WebView) context.findViewById(R.id.webView1);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.getSettings().setUseWideViewPort(true);
webView.loadUrl("http://docs.google.com/gview?embedded=true&url=http://www.stagecoachbus.com/PdfUploads/Timetable_28768_5.pdf");

It help you to show pdf.

like image 174
Md Abdul Gafur Avatar answered Dec 08 '25 18:12

Md Abdul Gafur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!