boazsegev / combine_pdf

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

Fix: TypeError: can't dup NilClass #180

Closed adam-e-trepanier closed 3 years ago

adam-e-trepanier commented 3 years ago

In the instance where the catalogs variable does not have a :ProcSet key, the code generates a new hash and assigns it to that key. It then tries to dup the value in that new hash for a key that does not exist. Other code above uses the inheritance_hash to dup when the data does not exists, and this follows that same flow.

EDIT: On further processing, when trying to create pages from a pdf loaded using inheritance_hash, it will raise an error. Simply using an empty array gets past the error and allows you to save individual pages.

adam-e-trepanier commented 3 years ago

This arose for me when I use wkhtmltopdf to turn EML(email) files into pdf after doing a little HTML manipulation. The way the code looks seems to me that the conditional branch has not used until now; otherwise, this error (I think) would have shown itself. I looked at the tests and am not sure how I would go about exercising this case. I am happy to share an example test file if needed for the bug to raise itself.

dhruvdesmond commented 3 years ago

Same issue with me. Please merge this.

randykipu commented 3 years ago

Upvote! All my PDF combinations get this error. I have edited my local gem to add a conditional check on line 582 of lib/combine_pdf/parser.rb, but that is a hack. I think this PR is the correct solution.

boazsegev commented 3 years ago

Hi @adam-e-trepanier ,

Thanks for the PR!

P.S.

Sorry for the belated merge... I don't really use CombinePDF anymore and I still hadn't found a maintainer for the gem. People use it, so it's still alive, but my memory of the PDF standard and this code-base is becoming hazier every day.

Anyway, thanks again!.

B.

randykipu commented 3 years ago

Thank you! We use your gem in several places, and in one of them this problem was causing exceptions 100% of the time.

adam-e-trepanier commented 3 years ago

Hi @adam-e-trepanier ,

Thanks for the PR!

P.S.

Sorry for the belated merge... I don't really use CombinePDF anymore and I still hadn't found a maintainer for the gem. People use it, so it's still alive, but my memory of the PDF standard and this code-base is becoming hazier every day.

Anyway, thanks again!.

B.

No worries @boazsegev, THANK YOU for your contribution to combine_pdf.