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?

Recommended Answers

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

Jump to Post

All 5 Replies

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 :)

Be a part of the DaniWeb community

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