We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

PDF with grouped checkboxes - how to determine which one to check

In my winform, I am opening a PDF with fields and trying to fill each field with the appropriate value.
The PDF has two checkboxes with the same field name 'check 2'.  One check box has the label 'Yes' and the 'No'.


The properties of the No check box:
     General tab  Name:'check 2'
     Options tab  Export Value 'no'

The properties of the Yes check box:
     General tab  Name:'check 2'
     Options tab  Export Value 'yes'


I have the two checkboxes defined as PdfLoadedCheckBoxItemCollection
I can't figure out how to determine which of the two PdfLoadedCheckBoxItem's in the list will export the value 'yes'.
I feel like I am so close but give up.

I couldn't attach my whole project so I included the pdf and project files, hoping you can see what I am doing.



Attachment: PdfClaimFillStuff_a1dab0c.zip

5 Replies

PV Prakash Viswanathan Syncfusion Team February 3, 2020 10:58 AM UTC

Hi Karla, 

Thank you for contacting Syncfusion support.  

We have checked the provided document and code snippet. The check box field items in the provided document does not have any different dictionary properties in file level. So, we could not differentiate with properties. However, we have analyzed further in the document structure level, the check box item in the 0th (zero) index is No and the item in 1st index on the collect is Yes. Based on the index on the PdfLoadedCheckBoxItemCollection, you can determine which one is checked.   

Please find the screenshot of the check box items under the name “check 2”, it does not have any difference in dictionary properties.  

 

Please let me know if you need any further assistance on this.  

Regards, 
Prakash V 



AK Andrey Kuznetsov September 26, 2022 11:15 AM UTC

I have a similar problem but from this article, it is not clear how do you find the values "Yes" and "No". The index for "Yes" could be 0 or 1 or 2 in a group of check-boxes and the item object does not have the values. In other words, how to find a connection/link/relation between "Yes" and index? Could you please clarify?

Thanks.



IJ Irfana Jaffer Sadhik Syncfusion Team September 27, 2022 12:34 PM UTC

Hi Andrey,

As we said earlier, we can able to get the check box field item based on the export value. Please find the below code snippet to find which item is checked based on the export value. Please try this on your end and let us know if it satisfies your requirement.


FileStream docStream = new FileStream("../../Data/form_b_410_0.pdf", FileMode.Open, FileAccess.Read);

PdfLoadedDocument loadedDocument = new PdfLoadedDocument(docStream);

 //Get the loaded form.

 PdfLoadedForm loadedForm = loadedDocument.Form;

string exportValue = "yes";

PdfLoadedField loadedField = null;

loadedDocument.Form.Fields.TryGetField("check 2", out loadedField);
PdfLoadedCheckBoxField loadedCheckBoxField = loadedField as PdfLoadedCheckBoxField;
PdfLoadedCheckBoxItem checkBoxItem = null;
loadedCheckBoxField.TryGetFieldItem(exportValue, out checkBoxItem);


checkBoxItem.Checked = true;

loadedDocument.Save("Output.pdf");

loadedDocument.Close();


Please let us know if you need any further assistance in this.


Regards,

Irfana J.



AK Andrey Kuznetsov October 11, 2022 11:44 AM UTC

Worked!

Thank you so much!



GK Gowthamraj Kumar Syncfusion Team October 11, 2022 11:59 AM UTC

Hi Andrey,


Thank you for your update. Please let us know if you need any further assistance in this.


Regards,

Gowthamraj K


Loader.
Live Chat Icon For mobile
Up arrow icon