Skip to content

Instantly share code, notes, and snippets.

@zudochkin
Last active August 29, 2015 14:25
Show Gist options
  • Save zudochkin/3a5240a684abe22ce174 to your computer and use it in GitHub Desktop.
Save zudochkin/3a5240a684abe22ce174 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# gem install pdf_forms
if ARGV.size < 2
puts "USAGE pdf-fill-out-checkboxes INPUT OUTPUT"
exit
end
require 'pdf_forms'
# On Linux
pdftk = PdfForms.new('/usr/bin/pdftk')
INPUT = ARGV.first
OUTPUT = ARGV.last
fields = pdftk.get_fields INPUT
data = {}
checkboxes = fields.select { |f| f.type != "Text" }.each { |f| data[f.name] = "Off" }
pdftk.fill_form INPUT, OUTPUT, data
puts "The following fields have been filled out :"
puts checkboxes.map(&:name).join(', ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment