Skip to content

Instantly share code, notes, and snippets.

@ArthurN
Created November 22, 2014 01:21
Show Gist options
  • Save ArthurN/e980d723a6d63e9fc766 to your computer and use it in GitHub Desktop.
Save ArthurN/e980d723a6d63e9fc766 to your computer and use it in GitHub Desktop.
pdf-reader-get-fields.rb
def get_fields
# We have to use #send because AFAIK, PDF::Reader does not expose the root object anywhere
acroform = @reader.send(:root)[:AcroForm]
# PDF::Reader encapsulates each piece of PDF data in #objects. The field_refs are really references to
# these objects. We iterate through and de-reference the actual object, creating a AcroField based on its
# data
field_refs = @reader.objects[acroform][:Fields] unless acroform.nil?
fields = field_refs.map do |field_ref|
AcroField.new(@reader.objects[field_ref])
end unless field_refs.blank?
fields
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment