Search code examples
ruby-on-railsrubypdftk

Checking checkbox with pdftk library in Ruby on Rails


I have an application when customer is registering and when he complete the registration he's got filled pdf template. To fill pdf templates I use this gem:

https://github.com/jkraemer/pdf-forms

But with this library I don't know how to check checkboxes. I have 2 checkboxes which customer can choose his gender. I'm trying to check it with this code:

   fill "topmostSubform[0].Page2[0].Antragst_Anrede[0]", "Male"
   fill "topmostSubform[0].Page2[0].Antragst_Anrede[1]", "Female"

But this not works. I can't find solution for this problem... Could somebody help me?


Solution

  • See the following issue from the pdf-forms Github:

    https://github.com/jkraemer/pdf-forms/issues/22

    In short, it depends on how the PDF is configured. At the terminal

    pdftk mypdf.pdf dump_data_fields
    

    should display all the form fields in the PDF. For the checkbox field in question (identified by FieldName), it should list the options available as a FieldStateOption. In my case, I had 'Off' and 'Yes' as FieldStateOptions, so calling

    fill :AwesomeField, 'Yes'
    

    resulted in AwesomeField being checked.