Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read PDF form data using iTextSharp?

Tags:

c#

forms

pdf

itext

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?

like image 742
Bhuvan Avatar asked Jul 29 '10 22:07

Bhuvan


People also ask

What is AcroFields in PDF?

The AcroFields are read from the document and saved to the database using a parameterized query, AcroFields are across the whole document and are not referenced per page. The following field data is saved in the database if the field has data: File name, Field name, Field value, Field type, File type.

What is ITextSharp used for?

Itextsharp is an advanced tool library which is used for creating complex pdf repors. itext is used by different techonologies -- Android , . NET, Java and GAE developer use it to enhance their applications with PDF functionality.

Is ITextSharp free?

This program is free software; you can redistribute it and/or modify it under the terms of the GNU Affero General Public License version 3 as published by the Free Software Foundation with the addition of the following permission added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK IN ...


1 Answers

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.

like image 136
cecilphillip Avatar answered Oct 13 '22 20:10

cecilphillip