简体   繁体   中英

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

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

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

Here's my code that get's 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 the field type from the AcroFields object? I know it has to be in there somewhere...

Was able to find field types this morning.

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);
}

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