Reputation: 26426
Let's say I've loaded a PDF file using iTextSharp:
PdfStamper p = GetDocument();
AcroFields af = ps.AcroFields;
How do I get a list of all field names on the document from af
?
Upvotes: 11
Views: 27649
Reputation: 111
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();
Upvotes: 11
Reputation: 186
It may just be me, but I am not getting .Value anymore.
foreach (var field in af.Fields)
{
Console.WriteLine(field.Key +" "+ af.GetField(field.Key));
}
Upvotes: 2
Reputation: 11586
foreach (DictionaryEntry entry in af.Fields) {
Console.WriteLine(entry.Key +" " +entry.Value);
}
Upvotes: 2
Reputation: 4643
AcroFields af = ps.AcroFields;
foreach (var field in af.Fields)
{
Console.WriteLine("{0}, {1}",
field.Key,
field.Value);
}
Upvotes: 15