我想解析一个包含复选框、单选按钮、下拉菜单和文本框的 PDF 文件。我想解析 PDF 文件以获取每个控件的位置和值。我正在使用 C# 和 itextsharp
任何建议/想法都会有所帮助。
到目前为止我所做的参考:http ://simpledotnetsolutions.wordpress.com/2012/04/08/itextsharp-few-c-examples/
public void ReadPDFformDataPageWise(string inputFile)
{
PdfReader reader = new PdfReader(inputFile);
AcroFields form = reader.AcroFields;
try
{
for (int page = 1; page <= reader.NumberOfPages; page++)
{
foreach (string key in form.Fields.Keys)
{
switch (form.GetFieldType(key))
{
case AcroFields.FIELD_TYPE_CHECKBOX:
//Create Checkbox
case AcroFields.FIELD_TYPE_COMBO:
//Create Combo Box
case AcroFields.FIELD_TYPE_LIST:
//Create List
case AcroFields.FIELD_TYPE_RADIOBUTTON:
//Create Radio button
case AcroFields.FIELD_TYPE_NONE:
case AcroFields.FIELD_TYPE_PUSHBUTTON:
//Create Submit Button
case AcroFields.FIELD_TYPE_SIGNATURE:
//Create Signature
case AcroFields.FIELD_TYPE_TEXT:
//Create textbox/Qs header
int fileType = form.GetFieldType(key);
string fieldValue = form.GetField(key);
float[] a = form.GetFieldPositions(key);
string translatedFileName = form.GetTranslatedFieldName(key);
AcroFields.Item test= form.GetFieldItem(key);
break;
}
}
}
}
catch
{
}
finally
{
reader.Close();
}
}