Method: PDF::Reader::ObjectHash#deref_string

Defined in:
lib/pdf/reader/object_hash.rb

#deref_string(key) ⇒ Object

If key is a PDF::Reader::Reference object, lookup the corresponding object in the PDF and return it. Otherwise return key untouched.

Guaranteed to only return a String or nil. If the dereference results in any other type then a MalformedPDFError exception will raise. Useful when expecting a string and no other type will do.

Some effort to cast to a string is made when the reference points to a non-string. : (untyped) -> String?



292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
# File 'lib/pdf/reader/object_hash.rb', line 292

def deref_string(key)
  obj = deref(key)

  return obj if obj.nil?

  if !obj.is_a?(String)
    if obj.respond_to?(:to_s)
      obj = obj.to_s
    else
      raise MalformedPDFError, "expected object to be a string"
    end
  end

  obj
end