Pdf.js can’t show PDF file they showing error message missing pdf 

Pdf.js can't show PDF file they showing error message missing pdf 

Hi, Developer in this Android article we share the solution Pdf.js can’t show PDF file they showing error message missing pdf. Like if you have used the PDF.js library for showing pdf files for the external stores. Show that current the have some update on the library they can not show file in web view Pdf.js can’t show PDF file they showing error message missing pdf.

PDF.js can’t show PDF from externalFilesDir at Android 11

current in existing implements pdf file not showing you are used pdf.js in android 6 and above. Pdf.js can’t show PDF files they showing an error message missing pdf. Hare, you can get a solution for this.

The solution was pretty simple (shame on me):

Up to API 29 I only used:

webView.settings.allowFileAccessFromFileURLs = true

Since API 30 I have to use:

webView.settings.allowFileAccessFromFileURLs = true
webView.settings.allowFileAccess = true

 

And any other issue you are facing

Open the local file in pdf.js android webview (“file” is not supported error)

This is any other issue in PDF.js to showing pdf in the issue is not supported error. So you can get a solution here.

Okay, this was a dumb question. I already put the following permissions in the manifest:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

But forgot that for API 23 and above you have to request permission at run time. So, just added the code to request permissions and it worked.

@TargetApi(23)
fun askPermissions() {
    val permissions = arrayOf("android.permission.READ_EXTERNAL_STORAGE", "android.permission.WRITE_EXTERNAL_STORAGE")
    val requestCode = 200
    requestPermissions(permissions, requestCode)
}

 

Facebooktwitterredditpinterestlinkedinmail
Recommended
Hi, let's start to learn more about the new Android.…