Handling checkboxes (or radio buttons for that matter) is not that different than populating text fields. Take the sample form below, from the itext site. Nothing fancy, just a simple form with some buttons and checkboxes. Initially, all of the boxes are un-checked. But with a few cfpdfformparam tags, you can easily mark them all as checked.
Source: iText in Action - Chapter 15 (Buttons)
Sample PDF: buttons.pdf
<!--- check all three checkboxes: Dutch, English, French --->
<cfpdfform action="populate" source="#ExpandPath('buttons.pdf')#">
<cfpdfformparam name="Dutch" value="On">
<cfpdfformparam name="English" value="On">
<cfpdfformparam name="French" value="On">
</cfpdfform>
I suspect the biggest gotcha is using the wrong "value". If you use an invalid value like "WhatTheHeckGoesHereToCheckThisDarnBox", when the form is expecting On/Off, obviously the box will not be checked.
Not to mention the fact that the "value" seems to case-sensitive. At least as far as I can tell. So if you accidentally used a lowercase "on" instead of "On", again the box will not be checked.
<!---
this FAILS because the expected "value" is case sensitive
ie The expected values are "On" not lowercase "on"
--->
<cfpdfform action="populate" source="#ExpandPath('buttons.pdf')#">
<!--- check all three checkboxes: Dutch, English, French --->
<cfpdfformparam name="Dutch" value="on">
<cfpdfformparam name="English" value="on">
<cfpdfformparam name="French" value="on">
</cfpdfform>
Just things to watch out for in the wonderful world of pdf forms.
- Related: Determining which values are allowed
I needed to do the exact same thing today, thanks for the heads up!
ReplyDeleteYou are welcome :)
ReplyDelete