-1

This is the error I am having in my logcat

E/PDFView: load pdf error
     java.io.IOException: cannot create document: File not in PDF format or corrupted.
         at com.shockwave.pdfium.PdfiumCore.nativeOpenMemDocument(Native Method)
         at com.shockwave.pdfium.PdfiumCore.newDocument(PdfiumCore.java:126)
         at com.github.barteksc.pdfviewer.source.InputStreamSource.createDocument(InputStreamSource.java:37)
         at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:53)
         at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:25)
         at android.os.AsyncTask$2.call(AsyncTask.java:288)
         at java.util.concurrent.FutureTask.run(FutureTask.java:237)
         at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
         at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
         at java.lang.Thread.run(Thread.java:841)
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Akshay Raut
  • 181
  • 2
  • 11

1 Answers1

1

That was reported in barteksc/AndroidPdfViewer issue 175

Had the same error. For some reason reading PDF directly from assets did not work, and gave the above mentioned error.

So copied it from asset to cache dir, and then all worked.

But first, double-check you can open that PDF file (independently of your execution environment, outside of your Java program).

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • my app is not created with the intention for reading PDFs form asstets folder , I am getting it from internet with URL link. – Akshay Raut Nov 24 '19 at 13:10
  • @AkshayRaut Did you test that link (independently from your Android environment) to see if there is a pfd behind said link? – VonC Nov 24 '19 at 13:11
  • Yes! my link is open and it runs on both pc and my android. I did test the pdf link in another browser of my android and it opens. – Akshay Raut Nov 24 '19 at 13:15
  • @AkshayRaut With the network panel of a chrome devtool (https://developers.google.com/web/tools/chrome-devtools/network), can you check if that link goes through redirection (https://stackoverflow.com/a/12282621/6309)? Maybe the library does not follow properly those URL redirection? – VonC Nov 24 '19 at 13:18