lib/combine_pdf/parser.rb in combine_pdf-0.2.33 vs lib/combine_pdf/parser.rb in combine_pdf-0.2.34

- old
+ new

@@ -118,13 +118,10 @@ @parsed << stream_data.shift end end end - # Strings were unified, we can let them go.. - @strings_dictionary.clear - # serialize_objects_and_references.catalog_pages # Benchmark.bm do |bm| # bm.report("serialize") {1000.times {serialize_objects_and_references} } # bm.report("serialize - old") {1000.times {old_serialize_objects_and_references} } @@ -133,10 +130,13 @@ serialize_objects_and_references catalog_pages + # Strings were unified, we can let them go.. + @strings_dictionary.clear + # collect any missing objects from the forms_data unless @forms_object.nil? || @forms_object.empty? @forms_object[:related_objects] = (@parsed.select { |o| o[:FT] }).map! { |o| { is_reference_only: true, referenced_object: o } } @forms_object[:related_objects].delete @forms_object end @@ -220,10 +220,12 @@ 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 fresh = true + # fix wkhtmltopdf use of PDF 1.1 Dest using symbols instead of strings + out.last[:Dest] = unify_string(out.last[:Dest].to_s) if out.last[:Dest] && out.last[:Dest].is_a?(Symbol) # puts "!!!!!!!!! Error with :indirect_reference_id\n\nObject #{out.last} :indirect_reference_id = #{out.last[:indirect_reference_id]}" unless out.last[:indirect_reference_id].is_a?(Integer) ########################################## ## parse a Hex String ########################################## elsif str = @scanner.scan(/<[0-9a-fA-F]*>/) @@ -392,10 +394,12 @@ 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 + # fix wkhtmltopdf use of PDF 1.1 Dest using symbols instead of strings + out.last[:Dest] = unify_string(out.last[:Dest].to_s) if out.last[:Dest] && out.last[:Dest].is_a?(Symbol) 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 @@ -487,9 +491,14 @@ catalog_pages(catalogs[:Kids], inheritance_hash.dup) unless catalogs[:Kids].nil? when :Catalog @forms_object.update((catalogs[:AcroForm][:referenced_object] || catalogs[:AcroForm]), &self.class.method(:hash_update_proc_for_new)) if catalogs[:AcroForm] @names_object.update((catalogs[:Names][:referenced_object] || catalogs[:Names]), &self.class.method(:hash_update_proc_for_new)) if catalogs[:Names] @outlines_object.update((catalogs[:Outlines][:referenced_object] || catalogs[:Outlines]), &self.class.method(:hash_update_proc_for_new)) if catalogs[:Outlines] + if catalogs[:Dests] # convert PDF 1.1 Dests to PDF 1.2+ Dests + dests_arry = (@names_object[:Dests] ||= {}) + dests_arry = ((dests_arry[:referenced_object] || dests_arry)[:Names] ||= []) + ((catalogs[:Dests][:referenced_object] || catalogs[:Dests])[:referenced_object] || (catalogs[:Dests][:referenced_object] || catalogs[:Dests])).each {|k,v| next if CombinePDF::PDF::PRIVATE_HASH_KEYS.include?(k); dests_arry << unify_string(k.to_s); dests_arry << v; } + end catalog_pages(catalogs[:Pages], inheritance_hash.dup) unless catalogs[:Pages].nil? end end end self