如何将 Android 中的大型 pdf 文件加载到我的 webview 中 [英] How to load large pdf file in Android into my webview

查看:28
本文介绍了如何将 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.

这篇关于如何将 Android 中的大型 pdf 文件加载到我的 webview 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆