class NdrImport::AcroFormReader

PDF AcroForm reader using the pdf-reader gem

Public Instance Methods

fields_hash() click to toggle source
# File lib/ndr_import/acroform_reader.rb, line 6
def fields_hash
  fields = {}
  fields_from(acroform[:Fields]).each do |field|
    field_name = field[:T]
    unless field[:Subtype] == :Widget || field.key?(:Kids)
      raise "Widgets or Radio boxes expected, found a #{field[:Subtype].inspect}"
    end
    raise "Non-unique column name #{field_name}" if fields.key?(field_name)
    fields[field_name] = field[:V]
  end
  fields
end

Private Instance Methods

acroform() click to toggle source
# File lib/ndr_import/acroform_reader.rb, line 21
def acroform
  @objects.deref(root[:AcroForm])
end
fields_from(refs) click to toggle source
# File lib/ndr_import/acroform_reader.rb, line 25
def fields_from(refs)
  Array(refs).flat_map do |ref|
    value = @objects[ref]
    # PDF has its own Hash class
    value.is_a?(::Hash) ? value : fields_from(value)
  end
end