lib/combine_pdf/parser.rb in combine_pdf-0.2.4 vs lib/combine_pdf/parser.rb in combine_pdf-0.2.5

- old
+ new

@@ -329,14 +329,30 @@ ########## ## skip untill end of segment, maked by %%EOF @scanner.skip_until(/\%\%EOF/) end - when @scanner.scan(/[\s]+/) , @scanner.scan(/obj[\s]*/) - # do nothing - # warn "White Space, do nothing" + when @scanner.scan(/[\s]+/) + # Generally, do nothing nil + when @scanner.scan(/obj[\s]*/) + # Fix wkhtmltopdf PDF authoring issue - missing 'endobj' keywords + unless out[-4].nil? || out[-4].is_a?(Hash) + keep = [] + keep << out.pop + keep << out.pop + + if out.last.is_a? Hash + out << out.pop.merge({indirect_generation_number: out.pop, indirect_reference_id: out.pop}) + else + out << {indirect_without_dictionary: out.pop, indirect_generation_number: out.pop, indirect_reference_id: out.pop} + end + warn "'endobj' keyword was missing for Object ID: #{out.last[:indirect_reference_id]}, trying to auto-fix issue, but might fail." + + out << keep.pop + out << keep.pop + end else # always advance # warn "Advnacing for unknown reason..." @scanner.pos = @scanner.pos + 1 end @@ -452,9 +468,14 @@ obj[:referenced_object] = obj_dir[ [obj[:indirect_reference_id], obj[:indirect_generation_number] ] ] warn "couldn't connect a reference!!! could be a null or removed (empty) object, Silent error!!!\n Object raising issue: #{obj.to_s}" unless obj[:referenced_object] obj.delete(:indirect_reference_id); obj.delete(:indirect_generation_number) end self + # rescue => e + # puts (@parsed.select {|o| !o.is_a?(Hash)}) + # puts (@parsed) + # puts (@references) + # raise e end # @private # this method reviews a Hash and updates it by merging Hash data, # preffering the old over the new. \ No newline at end of file