Created
November 22, 2014 01:21
-
-
Save ArthurN/e980d723a6d63e9fc766 to your computer and use it in GitHub Desktop.
pdf-reader-get-fields.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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