如何枚举ITextSharp中PDF文件中的所有字段

时间:2010-06-15 00:38:36

标签: c# pdf itextsharp

假设我使用iTextSharp加载了一个PDF文件:

PdfStamper p = GetDocument();
AcroFields af = ps.AcroFields;

如何从af获取文档中所有字段名称的列表?

4 个答案:

答案 0 :(得分:11)

AcroFields af = ps.AcroFields;

        foreach (var field in af.Fields)
        {
            Console.WriteLine("{0}, {1}",
                field.Key,
                field.Value);
        }

答案 1 :(得分:8)

PdfReader pdfReader = new PdfReader("c:\\ABC.pdf");

string TempFilename = Path.GetTempFileName();

AcroFields pdfFormFields = pdfReader.AcroFields;

foreach (KeyValuePair<string, AcroFields.Item> kvp in pdfFormFields.Fields)
{   
        string fieldName = kvp.Key.ToString();
        string fieldValue = pdfFormFields.GetField(kvp.Key.ToString());
        Console.WriteLine(fieldName + " " + fieldValue);
}

pdfReader.Close();

答案 2 :(得分:2)

foreach (DictionaryEntry entry in af.Fields) {
   Console.WriteLine(entry.Key +" " +entry.Value);
}

答案 3 :(得分:2)

可能只是我,但我没有得到.Value了。

foreach (var field in af.Fields)
{
    Console.WriteLine(field.Key +" "+  af.GetField(field.Key));
}