def fill_form(template, destination, data = {}, fill_options = {})
      q_template = normalize_path(template)
      q_destination = normalize_path(destination)
      fdf = data_format(data)
      tmp = Tempfile.new('pdf_forms-fdf')
      tmp.close
      fdf.save_to tmp.path
      fill_options = {:tmp_path => tmp.path}.merge(fill_options)

      args = [ q_template, 'fill_form', normalize_path(tmp.path), 'output', q_destination ]
      result = call_pdftk(*(append_options(args, fill_options)))

      unless File.readable?(destination) && File.size(destination) > 0
        fdf_path = nil
        begin
          fdf_path = File.join(File.dirname(tmp.path), "#{Time.now.strftime '%Y%m%d%H%M%S'}.fdf")
          fdf.save_to fdf_path
        rescue Exception
          fdf_path = "#{$!}\n#{$!.backtrace.join("\n")}"
        end
        raise PdftkError.new("failed to fill form with command\n#{pdftk} #{args.flatten.compact.join ' '}\ncommand output was:\n#{result}\nfailing form data has been saved to #{fdf_path}")
      end
    ensure
      tmp.unlink if tmp
    end
def fill_form(template, destination, data = {}, fill_options = {})
      q_template = normalize_path(template)
      q_destination = normalize_path(destination)
      fdf = data_format(data)
      tmp = Tempfile.new('pdf_forms-fdf')
      tmp.close
      fdf.save_to tmp.path
      fill_options = {:tmp_path => tmp.path}.merge(fill_options)

      args = [ q_template, 'fill_form', normalize_path(tmp.path), 'output', q_destination ]
      result = call_pdftk(*(append_options(args, fill_options)))

      unless File.readable?(destination) && File.size(destination) > 0
        fdf_path = nil
        begin
          fdf_path = File.join(File.dirname(tmp.path), "#{Time.now.strftime '%Y%m%d%H%M%S'}.fdf")
          fdf.save_to fdf_path
        rescue Exception
          fdf_path = "#{$!}\n#{$!.backtrace.join("\n")}"
        end
        raise PdftkError.new("failed to fill form with command\n#{pdftk} #{args.flatten.compact.join ' '}\ncommand output was:\n#{result}\nfailing form data has been saved to #{fdf_path}")
      end
    ensure
      tmp.unlink if tmp
    end
Initializes a new wrapper instance. Pdftk will be autodetected from PATH:
 PdftkWrapper.new(:flatten => true, :encrypt => true, :encrypt_options => 'allow Printing')

 The pdftk binary may also be explecitly specified:
 PdftkWrapper.new('/usr/bin/pdftk', :flatten => true, :encrypt => true, :encrypt_options => 'allow Printing')

 Besides the options shown above, the drop_xfa or drop_xmp options are
 also supported.
 pdftk.fill_form '/path/to/form.pdf', '/path/to/destination.pdf', :field1 => 'value 1'