简体   繁体   English

如何使用iTextSharp从PDF文档中的字段确定字段类型?

[英]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. 我正在用C#和VisualStudio试验iTextSharp库。 I'm trying to obtain field names and field types (TextBox, RadioButton, ComboBox, CheckBox) from the AcroFields object. 我正在尝试从AcroFields对象获取字段名称和字段类型(TextBox,RadioButton,ComboBox,CheckBox)。

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. 我已经检查了iText javadoc,因为这里有人说iTextSharp中的方法和功能应该类似但是没有发现是这种情况。

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? 关于如何从AcroFields对象中提取字段类型的任何想法? 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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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