如何将 Android 中的大型 pdf 文件加载到我的 webview 中
问题描述:
我无法将大型 pdf 文件(有 900 页)加载到我的webview 在我的 android 应用程序中,我尝试使用此代码并在任何其他 pdf,但是当我尝试打开一个较大的 pdf 时,它显示:无预览可用.
i am unable to load a large pdf file (having 900 page) into my webview in my android app, i try this code and working well on any other pdf, but when i try to open a large one it display: No Preview Available.
wvReport.getSettings().setJavaScriptEnabled(true);
wvReport.getSettings().setAllowFileAccess(true);
wvReport.getSettings().setAllowContentAccess(true);
wvReport.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
Toast.makeText(ReportsViewActivity.this, "Oh no! " , Toast.LENGTH_SHORT).show();
}
});
wvReport.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int progress) {
if (progress == 100) {
progressBar.setVisibility(View.INVISIBLE);
progressBar.setProgress(0);
} else {
progressBar.setVisibility(View.VISIBLE);
progressBar.setProgress(progress);
}
}
@Override
public void onReceivedTitle(WebView view, String title) {
}
});
wvReport.loadUrl("http://docs.google.com/viewer?url="+url);
答
试试这个代码:
Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(browserIntent);
并且它正在工作,所以如果pdf太大,将通过pdf查看器下载和打开.
and it's working, so if the pdf is too large , will be downloaded and opened via pdf viewer.