lib/pdf_filler.rb
# Given a PDF an array of fields -> values
# return a PDF with the given fields filled out
Given a PDF an array of fields -> values
return a PDF with the given fields filled out
Given a PDF an array of fields - > values return a PDF with the given fields filled out
def fill( url, data )
    source_pdf = open( URI.escape( url ) )
    step_1_result = Tempfile.new( ['pdf', '.pdf'] )
    filled_pdf = Tempfile.new( ['pdf', '.pdf'] )
    data = urldecode_keys data
    @pdftk.fill_form source_pdf.path, step_1_result.path, data.find_all{ |key, value| !key[KEY_REGEX] }
    Prawn::Document.generate filled_pdf.path, :template => step_1_result.path do |pdf|
      pdf.font("Helvetica", :size=> 10)
      fields = data.find_all { |key, value| key[KEY_REGEX] }
      fields.each do |key, value|
        at = key.match(KEY_REGEX)
        pdf.go_to_page at[:page].to_i || 1
        pdf.draw_text value, :at => [ at[ :x ].to_i, at[:y].to_i ]
      end
    end
    filled_pdf
  end
def fill ( url , data ) source_pdf = open ( URI . escape ( url ) ) step_1_result = Tempfile . new ( [ 'pdf' , '.pdf' ] ) filled_pdf = Tempfile . new ( [ 'pdf' , '.pdf' ] ) data = urldecode_keys data @pdftk . fill_form source_pdf . path , step_1_result . path , data . find_all { | key , value | ! key [ KEY_REGEX ] } Prawn :: Document . generate filled_pdf . path , :template => step_1_result . path do | pdf | pdf . font ( "Helvetica" , :size => 10 ) fields = data . find_all { | key , value | key [ KEY_REGEX ] } fields . each do | key , value | at = key . match ( KEY_REGEX ) pdf . go_to_page at [ :page ] . to_i || 1 pdf . draw_text value , :at => [ at [ :x ] . to_i , at [ :y ] . to_i ] end end filled_pdf end
Given a PDF an array of fields -> values
return a PDF with the given fields filled out
Given a PDF an array of fields - > values return a PDF with the given fields filled out
#Fill fillable fields (step 1) #Fill non-fillable fields (returning filled pdf)
url
<not_specific>
data
<not_specific>