lib/hexapdf/task/optimize.rb in hexapdf-0.20.1 vs lib/hexapdf/task/optimize.rb in hexapdf-0.20.2

- old
+ new

@@ -232,29 +232,29 @@ processor = SerializationProcessor.new HexaPDF::Content::Parser.parse(page.contents, processor) page.contents = processor.result page[:Contents].set_filter(:FlateDecode) xobjects = page.resources[:XObject] - processor.used_references.each {|ref| used_refs[xobjects[ref]] = true } + processor.used_references.each {|ref| used_refs[xobjects[ref]] = true } if xobjects end used_refs end # Deletes all XObject entries from the resources dictionaries of all pages whose names do not # match the keys in +used_refs+. def self.prune_page_resources(doc, used_refs) unless used_refs used_refs = {} doc.pages.each do |page| - xobjects = page.resources[:XObject] + next unless (xobjects = page.resources[:XObject]) HexaPDF::Content::Parser.parse(page.contents) do |op, operands| used_refs[xobjects[operands[0]]] = true if op == :Do end end end doc.pages.each do |page| - xobjects = page.resources[:XObject] + next unless (xobjects = page.resources[:XObject]) xobjects.each do |key, obj| next if used_refs[obj] xobjects.delete(key) end end