How to read PDF form data using iTextSharp?

后端 未结 5 1341
礼貌的吻别
礼貌的吻别 2020-12-03 07:39

I am trying to find out if it is possible to read PDF Form data (Forms filled in and saved with the form) using iTextSharp. How can I do this?

5条回答
  •  青春惊慌失措
    2020-12-03 08:39

    You would have to find out the field names in the PDF form. Get the fields and then read their value.

    string pdfTemplate = "my.pdf";
    PdfReader pdfReader = new PdfReader(pdfTemplate);
    AcroFields fields = pdfReader.AcroFields.Fields;
    string val = fields.GetField("fieldname");
    

    Obviously in the code above, field name is the name of the PDF form field and the GetField method returns a string representation of that value. Here is an article with example code that you could probably use. It shows how you can both read and write form fields using iTextSharp.

提交回复
热议问题