How to determine field type from field in PDF document using iTextSharp?

I am experimenting with the iTextSharp library with C # and VisualStudio. I am trying to get field names and field types (TextBox, RadioButton, ComboBox, CheckBox) from an AcroFields object.

Field names were easy to find, but I'm struggling with a field type. I checked iText javadoc because someone here said that the methods and functions should be similar in iTextSharp, but did not find that to be the case.

Here is my code that gets the field names:

FormObject fo = new FormObject(); List<FormField> form_fields = new List<FormField>(); PdfReader reader = new PdfReader(file_name); AcroFields reader_fields = reader.AcroFields; foreach (KeyValuePair<String, iTextSharp.text.pdf.AcroFields.Item> entry in reader_fields.Fields) { FormField ff = new FormField(); ff.Field_name = entry.Key.ToString(); form_fields.Add(ff); } 

Any ideas on how I can extract a field type from an AcroFields object? I know it must be somewhere there ...

+4
source share
1 answer

This morning we managed to find the types of fields.

 FormObject fo = new FormObject(); List<FormField> form_fields = new List<FormField>(); PdfReader reader = new PdfReader(file_name); AcroFields reader_fields = reader.AcroFields; foreach (KeyValuePair<String, iTextSharp.text.pdf.AcroFields.Item> entry in reader_fields.Fields) { FormField ff = new FormField(); ff.Field_name = entry.Key.ToString(); int field_type = reader_fields.GetFieldType(entry.Key.ToString()); form_fields.Add(ff); } 
+2
source

Source: https://habr.com/ru/post/1383722/


All Articles