Unable to open PDF documents in WebView

半城伤御伤魂 提交于 2019-12-29 06:30:18

问题


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!


回答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.




回答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.



来源:https://stackoverflow.com/questions/12803701/unable-to-open-pdf-documents-in-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!