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

混江龙づ霸主 提交于 2019-12-17 09:55:22

问题


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?


回答1:


AcroFields af = ps.AcroFields;

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



回答2:


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



回答3:


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



回答4:


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


来源:https://stackoverflow.com/questions/3041883/how-do-i-enumerate-all-the-fields-in-a-pdf-file-in-itextsharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!