android / graphics-samples

Multiple samples showing the best practices in graphics on Android.
Apache License 2.0
311 stars 134 forks source link

Cannot open PDF file after open wrong file #23

Open codingjeremy opened 5 years ago

codingjeremy commented 5 years ago

Issue by luongdolong Thursday May 24, 2018 at 03:57 GMT Originally opened as https://github.com/googlesamples/android-PdfRendererBasic/issues/25


I have a file: pdf.txt. I rename it to: pdf.pdf Below is my steps:

  1. Open app. Open file "sample.pdf". -> OK
  2. Open file "pdf.pdf" -> show Toast: "Error! file not in PDF format or corrupted"
  3. Open file "sample.pdf" again. -> show Toast: "Error! file not in PDF format or corrupted" Now I cannot open PDF file. If I kill app, and open app again. File "sample.pdf" show ok. And if I open wrong file. I cannot open any files more. How can I resolve this issue? Thank you
codingjeremy commented 5 years ago

Comment by msamyatl Wednesday Jun 20, 2018 at 03:14 GMT


@luongdolong same problem here. were you able to solve it?

codingjeremy commented 5 years ago

Comment by wywy4pm Wednesday Oct 17, 2018 at 08:34 GMT


the same problem.

codingjeremy commented 5 years ago

Comment by antonkovalyov351 Thursday Dec 20, 2018 at 09:05 GMT


+1

codingjeremy commented 5 years ago

Comment by AswinpAshok Tuesday Dec 25, 2018 at 14:45 GMT


Same issue. Any solutions?

codingjeremy commented 5 years ago

Comment by antonkovalyov351 Tuesday Dec 25, 2018 at 14:55 GMT


I used PdfiumAndroid library instead of default PdfRenderer. It doesn't have this issue.

codingjeremy commented 5 years ago

Comment by dikadk Wednesday Jan 09, 2019 at 19:10 GMT


+1

codingjeremy commented 5 years ago

Comment by dbland87 Tuesday Apr 02, 2019 at 20:08 GMT


+1 Has anyone found a good workaround for this?

codingjeremy commented 5 years ago

Comment by mnxamdev Wednesday May 22, 2019 at 19:44 GMT


This is a pretty serious issue. Seems like the ParcelFileDescriptor that is used as a constructor parameter is being held onto somehow and it keeps getting used instead of any new ones that are passed into any new instances of the PdfRenderer object. I would like to not have to use a third party library to display PDFs in my app.

codingjeremy commented 5 years ago

Comment by msamyatl Wednesday May 22, 2019 at 23:45 GMT


@mnxamdev the problem was fixed in android 28: https://issuetracker.google.com/issues/37052344

codingjeremy commented 5 years ago

Comment by mnxamdev Friday May 31, 2019 at 20:36 GMT


@mnxamdev the problem was fixed in android 28: https://issuetracker.google.com/issues/37052344

Thanks for the information, good to know. How can this be only fixed in Android 9??? What about the thousands of customers that we have that aren't on Android 9??? Is there some sort of work around which we can implement? Is there a way we can just get the PDF bytes and open that way?

codingjeremy commented 5 years ago

Comment by msamyatl Sunday Jun 02, 2019 at 21:40 GMT


Your best best is to probably use another pdf library to detect password-protected files.

On Sat, Jun 1, 2019 at 6:36 AM mnxamdev notifications@github.com wrote:

@mnxamdev https://github.com/mnxamdev the problem was fixed in android 28: https://issuetracker.google.com/issues/37052344

Thanks for the information, good to know. How can this be only fixed in Android 9??? What about the thousands of customers that we have that aren't on Android 9??? Is there some sort of work around which we can implement? Is there a way we can just get the PDF bytes and open that way?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/googlesamples/android-PdfRendererBasic/issues/25?email_source=notifications&email_token=AI4NT2EY3JZET33ZH2734NTPYGD4XA5CNFSM4FBODPFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODWWJ34I#issuecomment-497851889, or mute the thread https://github.com/notifications/unsubscribe-auth/AI4NT2FF54Y5ORCKXMXNNOLPYGD4XANCNFSM4FBODPFA .

codingjeremy commented 5 years ago

Comment by pgaikwad-os Thursday Aug 22, 2019 at 09:44 GMT


Still facing this issue in API-28 and API-29.

Stacktrace :

_2019-08-22 14:52:54.297 31420-31431/com.myandroid.app.debug E/System: Uncaught exception thrown by finalizer
2019-08-22 14:52:54.353 31420-31431/com.myandroid.app.debug E/System: java.io.IOException: file not in PDF format or corrupted
        at android.graphics.pdf.PdfRenderer.nativeClose(Native Method)
        at android.graphics.pdf.PdfRenderer.doClose(PdfRenderer.java:250)
        at android.graphics.pdf.PdfRenderer.finalize(PdfRenderer.java:238)
        at java.lang.Daemons$FinalizerDaemon.doFinalize(Daemons.java:250)
        at java.lang.Daemons$FinalizerDaemon.runInternal(Daemons.java:237)
        at java.lang.Daemons$Daemon.run(Daemons.java:103)
        at java.lang.Thread.run(Thread.java:764)_

Device Information: Pixel C - v8.1.0

Other links referred: https://github.com/voghDev/PdfViewPager/issues/101 >> https://github.com/voghDev/PdfViewPager/issues/101#issuecomment-452819867 https://issuetracker.google.com/issues/37052344

Any solution?

antoniogonzalezs commented 3 years ago

This is still happening with android Api 27. Any fix or workaround?

Edit: A workaround I implemented is to check first whether the file is a valid PDF by checking the file magic number: https://en.wikipedia.org/wiki/List_of_file_signatures