Unable to open PDF documents in WebView
10,697
Solution 1
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.
Solution 2
if u want to read pdf file offline
you can use mupdf-android library. it is good library.
I have used this in my one application. it is written in C. there instruction are given to make it workable.
Author by
Renjith
Updated on June 04, 2022Comments
-
Renjith almost 2 years
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!
-
Renjith over 11 yearsyeah, it will work. But wouldn't it work without google doc service?
-
Md Abdul Gafur over 11 yearsTo show pdf without google service > This post help you but you do not able to show in webview.>>stackoverflow.com/questions/6728920/…
-
Alfie Hanssen over 10 yearsGoogle docs approach doesn't seem to work for local PDF files, can you provide an example for local files?
-
shoke about 8 yearsThe google docs suggestion is terrible. You have this google docs reader that's designed for desktop in a tiny screen. How is this considered a good solution? Are all of you purposely designing ugly apps? Not user friendly at all. This solution should be illegal.