Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I enumerate all the fields in a PDF file in ITextSharp

Tags:

c#

pdf

itextsharp

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?

like image 922
Keltex Avatar asked Jun 15 '10 00:06

Keltex


2 Answers

AcroFields af = ps.AcroFields;

        foreach (var field in af.Fields)
        {
            Console.WriteLine("{0}, {1}",
                field.Key,
                field.Value);
        }
like image 114
S P Avatar answered Sep 28 '22 01:09

S P


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();
like image 35
Bhavin Shah Avatar answered Sep 27 '22 23:09

Bhavin Shah