Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fill_form not working #29

Closed
milesmatthias opened this issue Jun 18, 2015 · 2 comments
Closed

fill_form not working #29

milesmatthias opened this issue Jun 18, 2015 · 2 comments

Comments

@milesmatthias
Copy link

I'm trying to programmatically fill out this PDF: http://www.irs.gov/pub/irs-pdf/f1065sk1.pdf

and I'm seeing if your gem can help me. Here's the test script I'm using:

#!/usr/bin/env ruby

require 'pdf_forms'
require 'pry'

pdftk = PdfForms::PdftkWrapper.new('/usr/local/bin/pdftk')
pdf   = PdfForms::Pdf.new('2014_k1.pdf', pdftk)

field_names = pdf.fields.map(&:name)

field_values = field_names.map do |name|
  ret = {}
  ret[ name ] = name
  ret
end

pdftk.fill_form '2014_k1.pdf', 'filledout_k1.pdf', field_values

A PDF named filledout_k1.pdf is written to disk, but it doesn't have any fields filled out.

Do I need to convert the PDF to some other format to be able to fill it? I haven't done much with PDFs so I'm not sure how to go about it.

@jkraemer
Copy link
Owner

In your code field_values is an array of one-element hashes, but fill_form takes a single hash holding the data to fill in.

I think this

field_values = Hash[ pdf.fields.map{|f| [f.name, f.name]} ]

does what you want.

@milesmatthias
Copy link
Author

That worked, thanks for pointing out my oversight @jkraemer and nice work on this gem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants