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?

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)

Edited 2 Years Ago by Vitaliy_1: fixed mistypes

This article has been dead for over six months. Start a new discussion instead.