10

I am showing PDF files by using google docs in WebView in android. How to remove or hide "Sign In" button? I have attached screenshot below. Thanks in advance.

webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://docs.google.com/viewer?url=http://www.ex.com/terms.pdf");
webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});

enter image description here

selva_pollachi
  • 4,147
  • 4
  • 29
  • 42

4 Answers4

14

Add the embedded=true parameter.

webview = (WebView) findViewById(R.id.webView1);
webview.getSettings().setJavaScriptEnabled(true);
webview.loadUrl("https://docs.google.com/viewer?embedded=true&url=https://orimi.com/pdf-test.pdf");
webview.setWebViewClient(new WebViewClient() {
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return false;
    }
});

Note: This answer was actually proposed by user3777879. Tested, and working, he should get the credit - Stuart

Stuart Siegler
  • 1,686
  • 4
  • 30
  • 38
  • I've to open the pdf file saved in google drive using google docs. my drive link is `https://drive.google.com/file/d/0B0ecHy3Xov6tT0hINUZ5djRNZkk/view` if It's preceded with google docs format then it looks like `https://docs.google.com/viewer?embedded=true&url=https://drive.google.com/file/d/0B0ecHy3Xov6tT0hINUZ5djRNZkk/view` which is not a pdf file. How do I open this in google docs in pdf format – Prabs Aug 29 '16 at 19:36
  • @Prabs you should probably ask this in its own question. This answer is specific to this problem – Stuart Siegler Aug 30 '16 at 14:38
  • http://stackoverflow.com/questions/39220941/display-the-pdf-filestored-in-google-drive-in-webview-by-using-google-docs/ – Prabs Aug 31 '16 at 12:27
  • This doesn't work in the latest versions of Google Chrome. – FractalBob Apr 09 '22 at 10:04
8

Try this

I have tried to many answers but did not get good answer. Finally got the solution with adding few code in when loading the pdf into the webview .

 final WebView wv_webview= (WebView) view.findViewById(R.id.wv_webview);;
    wv_webview.getSettings().setJavaScriptEnabled(true);
    wv_webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            super.onPageStarted(view, url, favicon);
            wv_webview.loadUrl("javascript:(function() { " +
                    "document.querySelector('[role=\"toolbar\"]').remove();})()");
        }
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            wv_webview.loadUrl("javascript:(function() { " +
                    "document.querySelector('[role=\"toolbar\"]').remove();})()");
        }
    });
    String your_pdf_link="https://www.antennahouse.com/XSLsample/pdf/sample-link_1.pdf";
    wv_webview.loadUrl("https://docs.google.com/viewer?embedded=true&url=" + your_pdf_link);

Note:- It will show only few milliseconds when pdf loads into webview

Output:-enter image description here

Community
  • 1
  • 1
Sunil
  • 3,785
  • 1
  • 32
  • 43
2
webview.loadUrl("javascript:(function() { " +
                    "document.getElementsByClassName('drive-viewer-toolstrip')[0].style.visibility='hidden'; })()");
Android Tutorial
  • 829
  • 1
  • 8
  • 20
0

I'd self-host your terms document, and I'd host it as .html file format rather than .pdf.

If you do not have a domain in which to self-host the file, check other file hosting services and see if they offer a public option that won't request login. Potential services that may work for you include Mediafire, Cramitin, Hotfile, Rapidshare, etc. (this is not an ordered or comprehensive list, do your own search).

David Manpearl
  • 12,362
  • 8
  • 55
  • 72