boazsegev / combine_pdf

A Pure ruby library to merge PDF files, number pages and maybe more...
MIT License
734 stars 156 forks source link

root is unknown - cannot determine if file is Encrypted #89

Closed tbuyle closed 7 years ago

tbuyle commented 7 years ago

Hello,

When trying to open a PDF file, I ahev the error message "root is unknown - cannot determine if file is Encrypted"

It seems to be due to the PDF file being malformed since it's only happening with some PDF generated by one of my users (Single page PDF with an image inside them).

But all other sofwtare I try to read the PDF with have no issue : Chrome, Acrobat Reader, Photoshop CC ... so I don't really know what is wrong with the file.

Couldn't it be possible to open and combine the file even if the root object is missing ?

boazsegev commented 7 years ago

Hi @tbuyle and thank you for opening this issue.

I can't tell without looking at the PDF file if this is an issue (a bug), or something else. I also can't tell, without looking at a file, if I can write a patch to CombinePDF to work around this issue... will it be possible of you to send me an example file?

I should note that some limitations and differences exist between reading PDF content and editing it.

Since CombinePDF is used for basic PDF editing, I chose to design CombinePDF in a way that favors failure over the risk of PDF corruption.

If a class of PDF issues can be automatically fixed without risking PDF data corruption, I will try my best to write a patch, but otherwise I believe it better to fail than risk a corrupted PDF.

In general, without a Root object, it's impossible to know for sure if the data CombinePDF is accessing is encrypted (or not), so there's a risk of PDF corruption when editing such a file.

However, this might not be the case... this might be an issue. Without an example file, these are all theories :-/

Again, thank you for opening this issue. I hope we find a solution for this.

tbuyle commented 7 years ago

The PDF file is available at https://www.dropbox.com/s/6q60v7sqvydmxxz/Scan2.pdf

I perfectly understand that you may have to keep the current logic in order to avoid generating corrupted PDFs. So if this can not be changed, I'll simply have to educate my user on generating proper PDF :-D

Thanks for the great work on this gem.

boazsegev commented 7 years ago

@tbuyle ,

Hmmm... I can't seem to recreate the issue, it opens up just fine on my system...

What version of CombinePDF are you using? (Latest is 0.2.31)

tbuyle commented 7 years ago

Hello,

Sorry for the delay. I had to put this project on hold for a while.

I was using version 0.2.2 - I upgraded to 0.2.31 and it seems to solve the problem.

boazsegev commented 7 years ago

I'm happy the issue was resolved. :-) Good luck with your project!