【问题标题】:Want to go Specifc page in PDF using WebView想要使用 WebView 转到 PDF 中的特定页面
【发布时间】:2023-03-29 15:35:01
【问题描述】:

我正在使用 Web View 来显示 PDF,它工作正常但我想转到特定页面,但它不工作,因为在 WebView 中我们必须使用 URL,所以我在 URL 中传递我的页码在桌面浏览器上工作。即URL 否则,如果您知道在应用程序中显示 PDF 的任何其他方式,这将是最受欢迎的,但如果您谈论 barteck PDFviewer 库,由于体积庞大,它对我不起作用。我想要一个简单的轻量级 PDF 查看器,可以将我重定向到特定页面。任何建议都将受到欢迎。使用 webView 时,我的代码如下:

progressBar= findViewById(R.id.bar);
        webView= findViewById(R.id.webView);
        progressBar.setMax(100);

        Intent intent = getIntent();
        webView.setWebViewClient(new WebViewClient());
        String url= "https://www.holybooks.com/wp-content/uploads/2010/05/The-Holy-Bible-King-James-Version.pdf#page=4";
        webView.getSettings().setJavaScriptEnabled(true);
//        webView.hasFocus();
        webView.getSettings().setBuiltInZoomControls(true);

        webView.loadUrl(
                "https://docs.google.com/gvview?embedded=true&url="+ url);
        //https://drive.google.com/viewerng/viewer?embedded=true&url=
        //https://docs.google.com/gvview?embedded=true&url= #page=4
progressBar.setProgress(0);
webView.setWebChromeClient(new WebChromeClient(){
    @Override
    public void onProgressChanged(WebView view, int newProgress) {
        progressBar.setProgress(newProgress);
        if(newProgress==100){
            progressBar.setVisibility(View.INVISIBLE);
        }else
        {
            progressBar.setVisibility(View.VISIBLE);
        }
        super.onProgressChanged(view, newProgress);
    }
});

        int number = intent.getIntExtra("numberpg", 0);
        String number1 = String.valueOf(number);

    }
}

【问题讨论】:

  • am using Web View to Display PDF 这是不可能的,因为 WebView 一开始就无法显示 pdf 文档。
  • 那么如何去特定页面而不是bartacks库
  • am using Web View to Display PDF 如果我做了你所做的事情,我不仅会这么说。我会说我使用谷歌服务来转换 html 页面中的 pdf 文档并使用 WebView 来显示该 html。如前所述,webview 无法显示 pdf 文档。

标签: java android webview android-webview pdf-viewer


【解决方案1】:

你可以试试这个对我有用的库

pdf download and load pdf library process

https://www.geeksforgeeks.org/how-to-load-pdf-from-url-in-android/

这是 pdf 视图库

pdf library mention in the the blog(link) above

之后,您可以使用打开 pdf

pdfView.fromStream(InputStream).defaultPage(yourpagenumber).load

看完这两个链接,希望你能得到你想要的……

【讨论】:

  • 没有兄弟,那个库工作正常,但我有这个库的大小问题。这就是为什么我不得不选择其他方式来实现它。如果您知道如何减小尺寸,那将对我有所帮助
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-21
  • 1970-01-01
  • 2015-09-26
  • 1970-01-01
  • 2021-10-19
  • 1970-01-01
  • 2020-01-27
相关资源
最近更新 更多