boazsegev / combine_pdf

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

Broken when parsing PDF with empty object #217

Open sh-miyoshi opened 2 years ago

sh-miyoshi commented 2 years ago

Hi there, I found an error while parsing PDF.

When parsing a PDF file containing an empty object like following,

14 0 obj
<<
>>
endobj

...
/Resources 14 0 R

I got /Resources 0 0 R. PDF file does not contain 0 0 obj, so the PDF is broken. I suspect a bug in this method. https://github.com/boazsegev/combine_pdf/blob/master/lib/combine_pdf/renderer.rb#L92

Steps to reproduce

  1. Create pdf with empty object
    • I created pdf file by [Microsoft Print to PDF] in windows 10
  2. Run pdf_data = ::CombinePDF.parse(File.read(pdf_file)).to_pdf
  3. insert something to pdf_data

After this, I opened pdf by Acrobat Reader, and I found an error.