Issue
I am trying to load a PDF file via WebView
. I tried almost all the answers here in StackOverflow but still failed. Here is my resulting code:
WebView webView = findViewById(R.id.webView);
WebSettings settings = webView.getSettings();
settings.setAllowFileAccessFromFileURLs(true);
settings.setAllowUniversalAccessFromFileURLs(true);
settings.setBuiltInZoomControls(true);
webView.setContentDescription("application/pdf");
webView.loadUrl("file:///data/user/0/com.example.pdfwebviewer/files/masterlist.pdf");
I derived this code from a couple of sources:
- How to open local PDF file in WebView in Android?
- Can't open a local PDF in webview using file://
- Open PDF in a WebView
What did I miss?
Solution
It seems you have to try to use some library, because android-WebView doesn't seem to support .pdf
files.
So what Library
Alot of answers on this site like this one here recommends this library to read local pdf files:
Answered By - Hasan Bou Taam
Answer Checked By - David Goodson (JavaFixing Volunteer)