Android 中不显示 PDF
PDF does not display in Android
我已经将一些 pdf 文件上传到我的服务器并使用 url 在 Android 应用程序的 webview 中显示 pdf "http://docs.google.com/gview?embedded=true&url=myurl".
但我收到错误:
whooopss..Preview not available.
有时有效,有时却出现错误。我所有的 pdf 文件都是在 Acrobat 6.x 中制作的。
我使用了以下代码;
url = "http://docs.google.com/gview?embedded=true&url=" + url;
loadUrl(url);
private void loadUrl(String url){
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.loadUrl(url);
有时也会报错:
Web Console(2448): Uncaught ReferenceError: _init is not defined at
http://docs.google.com/gview?embedded=true&url=myurl/system/download/Datasheet_X1Carbon_2015f1201faba8ab0c3da16d9886ec8a0d1d.pdf:1
我对此进行了很多搜索,但找不到任何解决方案。
我不明白为什么会这样。对此的任何帮助都是可观的。
pdf显示方便。但有时应用程序没有足够的内存来加载整个 pdf。
您可以提供以下代码:
<application
android:name="pkg.name"
android:hardwareAccelerated="true"
android:largeHeap="true">
此处 android:largeHeap="true"
代码告诉系统为应用程序分配更多内存。但不是每次。
也有许多库可以单独显示 pdf Activity。
这是一个 Android-Pdf-Viewer-Library and documentation you may find here mupdf.com。
这是另一个库android-pdfview
我已经将一些 pdf 文件上传到我的服务器并使用 url 在 Android 应用程序的 webview 中显示 pdf "http://docs.google.com/gview?embedded=true&url=myurl".
但我收到错误:
whooopss..Preview not available.
有时有效,有时却出现错误。我所有的 pdf 文件都是在 Acrobat 6.x 中制作的。
我使用了以下代码;
url = "http://docs.google.com/gview?embedded=true&url=" + url;
loadUrl(url);
private void loadUrl(String url){
webView = (WebView) findViewById(R.id.webView1);
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setPluginState(PluginState.ON);
webView.loadUrl(url);
有时也会报错:
Web Console(2448): Uncaught ReferenceError: _init is not defined at http://docs.google.com/gview?embedded=true&url=myurl/system/download/Datasheet_X1Carbon_2015f1201faba8ab0c3da16d9886ec8a0d1d.pdf:1
我对此进行了很多搜索,但找不到任何解决方案。
我不明白为什么会这样。对此的任何帮助都是可观的。
pdf显示方便。但有时应用程序没有足够的内存来加载整个 pdf。
您可以提供以下代码:
<application
android:name="pkg.name"
android:hardwareAccelerated="true"
android:largeHeap="true">
此处 android:largeHeap="true"
代码告诉系统为应用程序分配更多内存。但不是每次。
也有许多库可以单独显示 pdf Activity。
这是一个 Android-Pdf-Viewer-Library and documentation you may find here mupdf.com。
这是另一个库android-pdfview