Display PDF into webview with autofill onReceivedHttpAuthentication of webview

I have PDF located in server which is secure on vpn and can be viewed with credential, I am trying to use webview to load it. whenever I hit that endpoint, it popup window for credential which I successfully autofill with onReceivedHttpAuthentication() overide method of webview. To load that pdf I am using webView.loadUrl(" https://docs.google.com/gview?embedded=true&url ="+ pdfUrl).

This do not load pdf in my webview. To check the problem I try to change the URL with without crednetial pdf which doesnt required any credential, this work fine, I can see the pdf in my webview.

What could be issue here? With the same credential I am able to view pdf in google chrome browser.

I am not surprised.

Not necessarily. The PDF needs to be publicly readable by anybody. So, not only are PDFs that are behind authentication a problem, so are PDFs that are not on the public Internet.

Primarily, you are relying on an undocumented and unsupported service that requires public access to your PDF to view it. With your solution, you need to allow Google to download the PDF to their servers and do whatever they want with that PDF, including (hopefully) serve it back to you via that undocumented and unsupported service.

My guess is that you are viewing the PDF directly, not via that docs.google.com URL. Chrome has a PDF renderer. WebView does not.

I wrote a blog post about PDF rendering options about three years ago. I expanded on that somewhat in a chapter in The Busy Coder’s Guide to Android Development. Both of those are a bit old, but they still are useful for seeing various options.

In the end, you will need to download the PDF (e.g., use OkHttp), then either let the user use their favorite PDF viewer app (via FileProvider and ACTION_VIEW) or embed a PDF renderer in your app.

Thank you so much for it clear all my doubts and answer all questions, we still didn’t see pdf support by google in 2020 like IOS have.