FDF - how to check a checkbox?
Asked Answered
A

6

18

I'm using FDF to populate a PDF template. On my PDF template, I have a checkbox and radio field called c1 and r1 respectively. What's the syntax I should use in my FDF file to check or select the c1 and r1 field?

I tried things like

<</T(c1)/V(1)>>
<</T(c1)/V(checked)>>
<</T(c1)/V(on)>>
<</T(c1)/V(true)>>

But none of them work.

Abdication answered 10/3, 2010 at 21:19 Comment(0)
A
23

I found the answer. To check, use

<</T(c1)/V(Yes)>>

To turn off, use

<</T(c1)/V(Off)>>

I found the answer on this page: http://www.4dcodeexchange.net/fdfformbuilder.htm

Excerpt

Checkboxes come in 2 flavors grouped and individual. Individual checkboxes will usually have a value of "Yes" or "Off". Grouped checkboxes are different in that each checkbox will have its own value. If you have problems with your FDF, look here first.

Abdication answered 10/3, 2010 at 21:40 Comment(5)
It should be noted here that 'Yes' is just a recommended way (PDF spec, p. 648) to tick a checkbox and not a surefire one. Though it'll most likely work for every form created with Acrobat.Davie
It should also be noted that even when using Adobe Acrobat, it is possible to change this value. In my version of Acrobat (version 9 for Mac), it is called "export value" and is found in the properties for each checkbox element.Syncom
This is the default value of PDFs created with the English Version of Adobe Acrobat; for German Version the checked value is per default "Ja" --> see Prof. Desty Nova's answerLozoya
@DanielKreiseder where should I see for Prof. Desty Nova's answer? I'm having a similar problem. In different PDFs the value needed to check the checkbox is different.Rabble
As mentioned in other comments, there are notable exceptions to using "Yes" to check the box...see Aku's answer for a solution to this. I guess the value for off/unchecked is inconsequential, since any value (including empty) other than the right one for on/checked will result in it not being checked.Culpa
R
19

The value passed to check the box is often "Yes" and "Off" - However, this is only the default value and it can be changed from "Yes" to almost any value at all (this is controlled by the export value of the document, as pointed out by others).

If you are looking to procedurally get the on/checked state value (which you will need to reliably set this checkbox as checked), it is contained in the appearances "AP" dictionary of the field. That dictionary should contain another dictionary "N", and each key is one of two values for the checkbox. The first key will be the unchecked value (usually "Off") and the second key will be the checked value (usually "Yes"). How you do this entirely depends on the API.

If you use pdftk from the command line, you can see what the expected values are using the command dump_data_fields: Eg.

pdftk document.pdf dump_data_fields 

Will show something like this:

---
FieldType: Button
FieldName: basform
FieldFlags: 0
FieldValue: No
FieldJustification: Left
FieldStateOption: Off
FieldStateOption: basic_forms            <---- Checked value expected by FDF

Here we can see that the checked state is actually expecting "basic_forms" and not "Yes". I believe the other state is always "Off", but that may depend on the language your program is using (the default "Yes" value certainly does).

Romanesque answered 14/3, 2016 at 1:6 Comment(3)
This answer does not handle the question about FDF directly, but it is the most informative one. It explains where the correct values for the checked and unchecked states are stored in the PDF, which is helpful if you want to write your own parser. But I have to make a small correction: The first entry in the /AP /N dictionary is not always /Off - in my PDF it is the second one.Feeble
I also found the first entry for FieldStateOption corresponded to the checked value, and "Off" came second. Fwiw: my PDF file was the US IRS Form 941. It has a group of checkboxes and each one has a different value for the "checked" FieldStateOption. PDFtk correctly shows both values, but the Python module pypdftk (version 0.4) converts the PDFtk dump_data_fields output to a list of Python dictionaries, so if there is more than one element in the same dictionary with the same key, only the last is kept...in my case losing the one I needed.Culpa
"it can be changed from Yes to almost any value at all" WTF Adobe?Livraison
S
12

Just to make a precision. It seems that to check an individual checkbox you need to use the export value you set when creating your box in Acrobat. This value is, indeed, by default to "Yes"

Slr answered 26/1, 2013 at 12:19 Comment(1)
+1000 Saved my Day completly. I think this is the only good answer in the internet.Maltzman
G
3

For all those for which above answers didn't work out I've been searching for a solution for a long time with PDF version 1.6. I then exported the form data (1) directly with Adobe Acrobat Pro DC and found another way which in the end worked out for me:

<</T(c1)/V/Off>> // this is non-checked
<</T(c1)/V/Yes>> // this is checked

As for the checked value (/Yes) this depends on the export value of the field. By standard the checkboxes in PDF forms have the value "yes" in the language your program is in.

Hope this helps others as well.


Footnote

(1) Important content from link:

You can use the "Prepare Form => More => Export data" to create an FDF file with the field name and data values. It will also contain the address of the PDF from which the data was extracted.

Gradient answered 9/7, 2020 at 15:4 Comment(1)
One type of checkbox on my form was a filled in box. This was On and Off. Another was a literal checkmark, and this was Yes and Off. Thank you for posting.Conurbation
S
0

For me works:

<</T(c1)/V(0)>>

for checked values and

<</T(c1)/V(Off)>>

values by default.

Subversion answered 18/7, 2013 at 8:57 Comment(0)
L
-3

Yes From JAVA ALSO we can pass value "Yes" to check the checkbox in pdf or fdf thanks.... Rachit Shah

Landeros answered 19/8, 2010 at 8:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.