Thursday, May 7, 2009

Populating CFPDFForm (Much ado about buttons and boxes)

I saw an interesting question on the adobe forums about populating a form with checkboxes. The question was how to check those darn checkboxes.

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.



2 comments:

Jeremy Gladwin,  May 8, 2009 at 7:41 AM  

I needed to do the exact same thing today, thanks for the heads up!

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Header image adapted from atomicjeep