2011-11-29 37 views
4

我正在用C#和VisualStudio试验iTextSharp库。我试图从AcroFields对象获取字段名称和字段类型(TextBox,RadioButton,ComboBox,CheckBox)。如何使用iTextSharp从PDF文档中的字段确定字段类型?

字段名称很容易找到,但我正在努力与字段类型。我检查过iText javadoc,因为这里有人说iTextSharp中的方法和函数应该是类似的,但是没有发现这种情况。

这里是我的代码,得到的字段名称:

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

我如何可以提取从AcroFields对象字段类型的任何想法?我知道它必须在那里...

+2

的[文档AcroFields(http://api.itextpdf.com/itext/com/itextpdf/text/pdf/AcroFields.html#getFieldType(java.lang.String中))似乎在暗示你使用'AcroFields.getFieldType()'而不是'AcroFields.Item'对象获取字段类型。 – millimoose

+0

我会明天感谢您的信息。 – pteranodonjohn

回答

2

今天早上能够找到字段类型。

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); 
} 
相关问题