Loading PDF in webView

时间:2018-07-25 08:17:02

标签: android

I created an App which shows a PDF File from their URL. I am able to show the PDF file in webview through this code.

  @Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
 //   setContentView(R.layout.activity_webview);

    WebView webView = new WebView(webview.this);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setPluginState(WebSettings.PluginState.ON);
    webView.setWebViewClient(new Callback());
    String pdf = "http://msbte.engg-info.website/sites/default/files/sem%20ii%20sample%20qp/22224-Applied-Mathematics-sample-question-paper.pdf";
    webView.loadUrl("http://docs.google.com/gview?embedded=true&url=" + pdf);
    setContentView(webView);
}

private class Callback extends WebViewClient {
    @Override
    public boolean shouldOverrideUrlLoading(
            WebView view, String url) {
        return (false);
    }
}

But I am having problem with the Open Plugin Button that shows on the upper right side of the screen. I want to disable that button but how is it possible.

Right Upper Side

Zoom in out

3 个答案:

答案 0 :(得分:0)

  

您可以重写此WebView的onPageFinished方法。像这样   下面-

String url = "javascript:(function() {"+"document.querySelector('[role=\"toolbar\"]').remove();})()"

     @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                yourWebView.loadUrl(url);
            }

它将删除该top_right按钮。

  

并删除缩放-

yourWebView.getSettings().setDisplayZoomControls(false);
yourWebView().setBuiltInZoomControls(false);

答案 1 :(得分:0)

您可以使用下面的库,但是它首先通过url下载pdf,然后本地保存到您的设备中,然后它将在pdfviewer视图中显示pdf。

https://github.com/voghDev/PdfViewPager

答案 2 :(得分:0)

使用 Google文档查看器打开您的PDF文件,如下所示

WebView webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true); 
String pdf = "http://www.adobe.com/devnet/acrobat/pdfs/pdf_open_parameters.pdf";
webview.loadUrl("http://drive.google.com/viewerng/viewer?embedded=true&url=" + pdf);