you can try pdf-stamper. I am working on filling out the pdf form fields now.here is my solution.
@template = PDF::Stamper.new(@form.pdf.current_path)
fields = @template.extract_fields
@form.form_fields.each do |ff|
if fields.has_key?(ff.pdf_field)
val = form_data.get_value(ff)
render_field(@template, ff, val)
else
BindFile.logger.warn "Key '#{ff.pdf_field}' Not Found".center(100, "-")
end
end
def render_field(templet, form_field, val)
if val.present?
case form_field.pdf_field_type
when "CheckBox"
if val.present?
templet.checkbox form_field.pdf_field
end
when "RadioButton"
templet.send("radio_button", form_field.pdf_field, "Yes")
when "", nil
templet.send "text", form_field.pdf_field, val
else
templet.send(form_field.pdf_field_type.to_s.downcase, form_field.pdf_field, val)
end
end
end
here I raised pdf-stamper by adding the method "extract_fields". and use a database record to manage pdf documents. hope useful for you.
source
share