问题
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