Skip to content

Instantly share code, notes, and snippets.

@akiellor
Created January 24, 2020 19:40
Show Gist options
  • Save akiellor/1987bb1688ea2e85dbc27cc4c6361db1 to your computer and use it in GitHub Desktop.
Save akiellor/1987bb1688ea2e85dbc27cc4c6361db1 to your computer and use it in GitHub Desktop.
reader = PDF::Reader.new('some.pdf')
filename = "transactions.csv" # obtain this from the XFA in the pdf
page = reader.pages.first
attachment_name_reference = page.objects.find do |k, v|
page.objects.obj_type(k) == :Hash && v[:Type] == :Filespec && v[:UF] == filename }.first
end
attachment_content_reference = page.objects[attachment_name_reference][:EF][:F]
attachment_content = page.objects[attachment_content_reference].unfiltered_data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment