'Pdf file is not able to load in android webview but able to load in external browser
I have the webpage created with angular js file. There are pdf files inside the webpage we want to download and show. when clicking the pdf file, it just show loading and nth happened. Also shouldOverrideUrlLoading method is never called. This method is not deprecated. We tried to load the url in external browser and open the pdf, it successfully download and open the pdf file. I would like to know is there any webview setting I missed out? current webview settings in my implementation is as below . Kindly help. thank you
webView?.settings?.builtInZoomControls = true
webView?.settings?.domStorageEnabled = true
webView?.settings?.allowFileAccess = true
webView?.settings?.allowContentAccess = true
Solution 1:[1]
You should try this one might be it work by WebViewClient
.
Check out this -- https://stackoverflow.com/a/14201778/18858169
Solution 2:[2]
PDF is a file format NOT handled by WebView
, it's designed to show web content, not some documents
if you really want to show PDF inside WebView
then you should use some web application, which can take a PDF file (or URL pointing on some) and render content of your file in a "web way", thus WebView
could print it
for example Google have such web app and you can open PDFs in it using some of below URLs (these may changed)
https://docs.google.com/viewer?url=http://customdomain.com/pdffile.pdf
https://docs.google.com/gview?embedded=true&url=http://customdomain.com/pdffile.pdf
https://drive.google.com/viewerng/viewer?embedded=true&url=http://customdomain.com/pdffile.pdf
note that you are basing on 3rd-party service - your PDF may be online, but 3rd-party companys server-side may be down or changed routing and your hardcoded URL prefix stop working
and if you want to show "real" PDF then use PdfRenderer
class, which will give you a set of Bitmap
s, which can be shown with ImageView
, no WebView
needed
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Bhavin Solanki |
Solution 2 | snachmsm |