def secure_for_copy
      # initiate dictionary from old names to new names
      names_dictionary = {}

      # travel every dictionary to pick up names (keys), change them and add them to the dictionary
      res = resources
      res.each do |k, v|
        next unless actual_value(v).is_a?(Hash)
        # if k == :XObject
        # 	self[:Resources][k] = v.dup
        # 	next
        # end
        new_dictionary = {}
        new_name = 'Combine' + SecureRandom.hex(7) + 'PDF'
        i = 1
        actual_value(v).each do |old_key, value|
          new_key = (new_name + i.to_s).to_sym
          names_dictionary[old_key] = new_key
          new_dictionary[new_key] = value
          i += 1
        end
        res[k] = new_dictionary
      end

      # now that we have replaced the names in the resources dictionaries,
      # it is time to replace the names inside the stream
      # we will need to make sure we have access to the stream injected
      # we will user PDFFilter.inflate_object
      self[:Contents].each do |c|
        stream = actual_value(c)
        PDFFilter.inflate_object stream
        names_dictionary.each do |old_key, new_key|
          stream[:raw_stream_content].gsub! object_to_pdf(old_key), object_to_pdf(new_key) ##### PRAY(!) that the parsed datawill be correctly reproduced!
        end
        # # # the following code isn't needed now that we wrap both the existing and incoming content streams.
        # # patch back to PDF defaults, for OCRed PDF files.
        # stream[:raw_stream_content] = "q\n0 0 0 rg\n0 0 0 RG\n0 Tr\n1 0 0 1 0 0 cm\n%s\nQ\n" % stream[:raw_stream_content]
      end
      self
    end
def secure_for_copy
      # initiate dictionary from old names to new names
      names_dictionary = {}

      # travel every dictionary to pick up names (keys), change them and add them to the dictionary
      res = resources
      res.each do |k, v|
        next unless actual_value(v).is_a?(Hash)
        # if k == :XObject
        # 	self[:Resources][k] = v.dup
        # 	next
        # end
        new_dictionary = {}
        new_name = 'Combine' + SecureRandom.hex(7) + 'PDF'
        i = 1
        actual_value(v).each do |old_key, value|
          new_key = (new_name + i.to_s).to_sym
          names_dictionary[old_key] = new_key
          new_dictionary[new_key] = value
          i += 1
        end
        res[k] = new_dictionary
      end

      # now that we have replaced the names in the resources dictionaries,
      # it is time to replace the names inside the stream
      # we will need to make sure we have access to the stream injected
      # we will user PDFFilter.inflate_object
      self[:Contents].each do |c|
        stream = actual_value(c)
        PDFFilter.inflate_object stream
        names_dictionary.each do |old_key, new_key|
          stream[:raw_stream_content].gsub! object_to_pdf(old_key), object_to_pdf(new_key) ##### PRAY(!) that the parsed datawill be correctly reproduced!
        end
        # # # the following code isn't needed now that we wrap both the existing and incoming content streams.
        # # patch back to PDF defaults, for OCRed PDF files.
        # stream[:raw_stream_content] = "q\n0 0 0 rg\n0 0 0 RG\n0 Tr\n1 0 0 1 0 0 cm\n%s\nQ\n" % stream[:raw_stream_content]
      end
      self
    end
copy_and_secure_for_injection(page)
 - page is a page in the pages array, i.e.
   pdf.pages[0]
 takes a page object and:

 makes a deep copy of the page (Ruby defaults to pointers, so this will copy the memory).

 then it will rewrite the content stream with renamed resources, so as to avoid name conflicts.