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

Password option not working #282

Closed
danielobasi opened this issue May 2, 2017 · 14 comments
Closed

Password option not working #282

danielobasi opened this issue May 2, 2017 · 14 comments
Labels

Comments

@danielobasi
Copy link

danielobasi commented May 2, 2017

I'm working on a project that requires a password protected pdf but when i put the correct password the pdf doesn't load and i get this error in android monitor:
E/PDFView: load pdf error java.io.IOException: File is empty
at com.shockwave.pdfium.PdfiumCore.nativeOpenDocument(Native Method)
at com.shockwave.pdfium.PdfiumCore.newDocument(PdfiumCore.java:107)
at com.github.barteksc.pdfviewer.source.FileSource.createDocument(FileSource.java:38)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:49)
at com.github.barteksc.pdfviewer.DecodingAsyncTask.doInBackground(DecodingAsyncTask.java:25)
at android.os.AsyncTask$2.call(AsyncTask.java:295)
at java.util.concurrent.FutureTask.run(FutureTask.java:237)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at java.lang.Thread.run(Thread.java:818)

Although it works without password.
I use this for the pdf reader.
readerView.fromFile(mBook)
.enableSwipe(true)
.swipeHorizontal(true)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(false)
.password("08034283779")
.defaultPage(pageNumber)
.onPageChange(this)
.onLoad(this)
.scrollHandle(new DefaultScrollHandle(this))
.load();

Is there a different way of using passwords?

@1stmetro
Copy link

1stmetro commented May 5, 2017

simply

.password(pass)

is correct, but you catch the errors are you sure the password is correct ?

Forward the pdf can test on my app if you wish ?

@danielobasi
Copy link
Author

CSE 000-3-COMPUTER ENGLISH.pdf
That is the file, Please check, Thanks a lot .
I can open it with the password on pages without any problems.

@1stmetro
Copy link

1stmetro commented May 6, 2017

It's what I thought it was when you do not use the correct password it will error that's normal just catch the error and display to the user that the password is incorrect works fine for me a blue background pdf file when opened and my message saying pdf requires a correct password if I do not set one.

@danielobasi
Copy link
Author

Please can you send me a sample of your activity that reads the pdf. What I have there, the password showed on my code is what I used and it's not working on mine, if it's working on yours I need to see your implementation. On mine with that password I get a blank screen when trying to read the pdf and that error shows on my android monitor.

@1stmetro
Copy link

1stmetro commented May 7, 2017

if you have the correct password and the page is white that's a bit strange, if you have the wrong pass it will error out which is what you catch, i would work on the basics which is the .password(pass) bit and then work on the error catching.

readerView.fromFile(mBook) <-- have you checked the path to the file, as your error reads "load pdf error java.io.IOException: File is empty" i dont believe it gives this error on an incorrect password although its a while since i played around with error catching...

@danielobasi
Copy link
Author

Thanks alot. I have the correct password, the page is white, it's not a path error because if I remove the password it works. What do you mean:
"if you have the correct password and the page is white that's a bit string"
I don't understand. I think that's the error , how can I be sure to use the same string type ?

@1stmetro
Copy link

1stmetro commented May 7, 2017

The string bit meant to say strange that was a typo, i basically have the same as you have used, but you have applied the default page twice ? is the second one a null or an invalid page ?

.password(password) - password is a string, i actually restore it from a database and apply it to the loaded pdf.

readerView.fromFile(mBook)
.enableSwipe(true)
.swipeHorizontal(true)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(false)
.password("08034283779")
.defaultPage(pageNumber) ------ What page is this ? since you have set it twice ie blank page ?
.onPageChange(this)
.onLoad(this)
.scrollHandle(new DefaultScrollHandle(this))
.load();

@danielobasi
Copy link
Author

Sorry that is not a blank page . It was a mistake after I implemented code to store the last page number in database and resume after a user comes back. It's not a blank page, my screen is just white and in monitor I see "file is empty" only when i use a password with the pdf.
I've loaded the password from a string variable and it still doesn't work.

@1stmetro
Copy link

1stmetro commented May 7, 2017

i have experienced issues using fragments but not one with using a password in a fragment.

Just start basic and use the default instructions on here, it will probably work without any issues thats how i know there is issues using fragments, but no everyone gets the same issues.

some use fragments with no problem's just depends what else you are doing i guess.

@danielobasi
Copy link
Author

Ok. But I'm using an activity and not a fragment. The problem exist only when I try to use a password. I guess it's not matching the password correctly because the error I get is the same when I intentionally try a wrong password. I guess I'll have to look through the sources for the implementation of the password for pdf. Thanks alot

@1stmetro
Copy link

1stmetro commented May 7, 2017

Dunno if this my help

"Am trying a populate a pdf which is stored in internal storage is throwing FileNotFoundException."

Simular issues to what you have as file not could found or empty.

#2

@danielobasi
Copy link
Author

I uploaded the pdf on a backend, download it to the phone using the app, store the name and path of the pdf in database, take the file path from the database and pass it to the read. It's just one implementation and it works without password but with password if gives that file empty error. If it's a path thing or some other errors other pdf that aren't locked won't also load, but they load.

@danielobasi
Copy link
Author

I've found the issue, has nothing to do with the library. it was a blank space on the path i didn't notice. It works now. Thanks a lot.

@1stmetro
Copy link

1stmetro commented May 8, 2017

I did say check the path..... good luck with your app !

Now you gotta catch the wrong password !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants