简体   繁体   中英

Multiple checkbox are checked when selecting single checkbox in iTextShap

I want to create a editable pdf which has multiple check box below is the code if i check one check box all are getting checked.

PdfPCell tbCellck3 = new PdfPCell(new Phrase("", helvetica12));
tbCellck3.Colspan = 1;
RadioCheckField checkBox3 = new RadioCheckField(writer, new iTextSharp.text.Rectangle(5, 5), "noDelete", "Yes");
checkBox3.CheckType = RadioCheckField.TYPE_CHECK;
PdfFormField field3 = checkBox3.CheckField;
writer.AddAnnotation(field3);
iTextSharp.text.pdf.events.FieldPositioningEvents eventscheckBox3 = new   iTextSharp.text.pdf.events.FieldPositioningEvents(writer, field3);
tbCellck3.CellEvent = eventscheckBox3;
subAEtable.AddCell(tbCellck3);
PdfPCell tbCellP6 = new PdfPCell(new Phrase("Substitution approved as noted - Make submittals in accordance with Specification Section 01 25 00 Substitution Procedures.", helvetica12));
tbCellP6.Colspan = 3;
tbCellP6.Border = PdfCell.NO_BORDER;
 subAEtable.AddCell(tbCellP6);

PdfPCell tbCellck4 = new PdfPCell(new Phrase("", helvetica12));
 tbCellck4.Colspan = 1;
RadioCheckField checkBox4 = new RadioCheckField(writer, new iTextSharp.text.Rectangle(5, 5), "noDelete", "Yes");
checkBox4.CheckType = RadioCheckField.TYPE_CHECK;
PdfFormField field4 = checkBox4.CheckField;
writer.AddAnnotation(field4);
iTextSharp.text.pdf.events.FieldPositioningEvents eventscheckBox4 = new     iTextSharp.text.pdf.events.FieldPositioningEvents(writer, field4);
tbCellck4.CellEvent = eventscheckBox4;
subAEtable.AddCell(tbCellck4);
PdfPCell tbCellP7 = new PdfPCell(new Phrase("Substitution rejected - use specified materials.", helvetica12));
tbCellP7.Colspan = 3;
tbCellP7.Border = PdfCell.NO_BORDER;
subAEtable.AddCell(tbCellP7);

You (probably by accident) used the autofill functionality. The reason is the same name noDelete which is the 3rd parameter of the RadioCheckField constructor.

RadioCheckField checkBox3 = new RadioCheckField(writer, new iTextSharp.text.Rectangle(5, 5), "noDelete", "Yes");
checkBox3.CheckType = RadioCheckField.TYPE_CHECK;
PdfFormField field3 = checkBox3.CheckField;
writer.AddAnnotation(field3);

RadioCheckField checkBox4 = new RadioCheckField(writer, new iTextSharp.text.Rectangle(5, 5), "noDelete", "Yes");
checkBox4.CheckType = RadioCheckField.TYPE_CHECK;
PdfFormField field4 = checkBox4.CheckField;
PdfFormField field4 = checkBox4.CheckField;
writer.AddAnnotation(field4);

If you change it to unique names (like noDelete1 and noDelete2 you'll get your desired behavior:

RadioCheckField checkBox3 = new RadioCheckField(writer, new iTextSharp.text.Rectangle(5, 5), "noDelete1", "Yes");
checkBox3.CheckType = RadioCheckField.TYPE_CHECK;
PdfFormField field3 = checkBox3.CheckField;
writer.AddAnnotation(field3);

RadioCheckField checkBox4 = new RadioCheckField(writer, new iTextSharp.text.Rectangle(5, 5), "noDelete2", "Yes");
checkBox4.CheckType = RadioCheckField.TYPE_CHECK;
PdfFormField field4 = checkBox4.CheckField;
PdfFormField field4 = checkBox4.CheckField;
writer.AddAnnotation(field4);

One additional hint: Try to find meaningful names which describe the field. Eg 'AgreementCheck', "SurveyOptionA" and so on. This helps when later the form data is extracted and evaluated.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM