Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot open PDF file after open wrong file #23

Open
codingjeremy opened this issue Sep 6, 2019 · 13 comments
Open

Cannot open PDF file after open wrong file #23

codingjeremy opened this issue Sep 6, 2019 · 13 comments
Labels
migrated googlesamples Migrated from old googlesamples repos PdfRendererBasic

Comments

@codingjeremy
Copy link
Collaborator

Issue by luongdolong
Thursday May 24, 2018 at 03:57 GMT
Originally opened as googlearchive/android-PdfRendererBasic#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
Copy link
Collaborator Author

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


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

@codingjeremy
Copy link
Collaborator Author

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


the same problem.

@codingjeremy
Copy link
Collaborator Author

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


+1

@codingjeremy
Copy link
Collaborator Author

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


Same issue. Any solutions?

@codingjeremy
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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


+1

@codingjeremy
Copy link
Collaborator Author

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


+1
Has anyone found a good workaround for this?

@codingjeremy
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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
Copy link
Collaborator Author

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 [email protected] 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
googlearchive/android-PdfRendererBasic#25,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AI4NT2FF54Y5ORCKXMXNNOLPYGD4XANCNFSM4FBODPFA
.

@codingjeremy
Copy link
Collaborator Author

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:
voghDev/PdfViewPager#101 >> voghDev/PdfViewPager#101 (comment)
https://issuetracker.google.com/issues/37052344

Any solution?

@codingjeremy codingjeremy added the migrated googlesamples Migrated from old googlesamples repos label Sep 18, 2019
@antoniogonzalezs
Copy link

antoniogonzalezs commented Sep 15, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
migrated googlesamples Migrated from old googlesamples repos PdfRendererBasic
Projects
None yet
Development

No branches or pull requests

3 participants