Hello everyone, I am currently working on a project for a friend and have encountered some issues. I am attempting to fill out a form with a library called iTextsharp: http://itextpdf.com/ The form that I am attempting to fill out is http://www.copyright.gov/forms/formco2d.pdf and I have been able to fill out the text input fields, however I have not been able to figure out how to check the checkboxes. The code I am using is as follows:

string formFile = @"C:\Users\Owner\Documents\formco2d.pdf";
            string newFile = @"C:\Users\Owner\Documents\formco2dfilledout.pdf";
            PdfReader reader = new PdfReader(formFile);
            PdfStamper stamper = new PdfStamper(reader, new FileStream(newFile, FileMode.Create));
            AcroFields fields = stamper.AcroFields;

            // set form fields
            fields.SetField("serial_1a", "True");
            fields.SetField("f1b", "Title Of Work");
            fields.SetField("f1cv", "Volume");
            fields.SetField("f1cn", "Number");
            fields.SetField("f1ci", "Issue");

            stamper.Close();
            button1.Text = "Done";

That code fills out the fields just fine, but has no effect on the actual checkboxes. I have tried sending True, 1, Active, etc to them but nothing makes them active.

Does anyone have any ideas on what I might be able to do about this?

The default Checkbox field export value is "Yes". Did you try this?

I have tried yes, however it does not take that either, the box stays unchecked.

Sorry to bump, but this is still causing me major problems, does anyone have any experience with iTextSharp and can maybe help?

the pdf filed has an Export Value on Options tab. To set a check box with iTextSharp you should pass this value as a second parameter into the SetField method (for CheckBox default is On)

You can use PDFEscape to get the Export value you need.

You upload your PDF file, you right click on a check box, you unlock it, then you right click again to get the object properties. It will open a window with the name of check box and the export value needed.

It avoids you to pay for an adobe license :)

Sorry to resurrect an old thread, but this thread gets about the closest I've seen to the question/issue I'm having (I've not been able to find a definite answer).

My question is - is the export value case-sensitive? For a checkbox - if the export value is "Yes", will supplying a value of "yes" or "YES" in the SetField statement cause the checkbox to be checked?

Thanks for any help - again, sorry to bring up an old thread

commented: Dim MyPDFFormCheckBoxField As Fields.PdfFormField = myform.GetField("myCheckBox") MyPDFFormCheckBoxField.SetCheckType(Pdf +0

try this:

Dim MyPDFFormCheckBoxField As Fields.PdfFormField = myform.GetField("myCheckBox")
MyPDFFormCheckBoxField.SetCheckType(PdfFormField.TYPE_CHECK)
MyPDFFormCheckBoxField.SetValue("", If(myCheckBox.IsChecked = True, True, False))

This:
If(myCheckBox.IsChecked = True, True, False)
is what actually check or not the checkbox on the PDF, notice this is the second paramenter of SetValue!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.