开发者

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

Let's say I've loaded a PDF file using iTextSharp:

PdfStamper p 开发者_C百科= GetDocument();
AcroFields af = ps.AcroFields;

How do I get a list of all field names on the document from af?


AcroFields af = ps.AcroFields;

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


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


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


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜