0

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:

  1. How to open local PDF file in WebView in Android?
  2. Can't open a local PDF in webview using file://
  3. Open PDF in a WebView

What did I miss?

user1506104
  • 5,648
  • 2
  • 59
  • 76

1 Answers1

0

It seems you have to try to use some library, because android-WebView doesn't seem to support .pdf files.

  1. Mentioned here
  2. Mentioned here in a comment to the main question

So what Library

Alot of answers on this site like this one here recommends this library to read local pdf files:

AndroidPdfViewer

Hasan Bou Taam
  • 3,911
  • 2
  • 9
  • 21