Using iText Sharp to read a PDF Form and get the Signature Information

Crystal Rouse
Crystal Rouse used Ask the Experts™
on
I need to get Certificate Info from a PDF Form.  Not sure how to do this with iTextSharp.

Here is some sample code:

[HttpPost]
        public ActionResult Upload(HttpPostedFileBase file, string Name)
        {

            if (file != null && file.ContentLength > 0)
            {
                    string pdfTemplate = "NewRequest.pdf";
                    byte[] pdfbytes = null;

                    BinaryReader rdr = new BinaryReader(file.InputStream);
                    pdfbytes = rdr.ReadBytes((int)file.ContentLength);
                    PdfReader reader = new PdfReader(pdfbytes);
                    //PdfReader _reader = new PdfReader((byte[])file).ToArray();

                    string t = Name.Trim().Length == 0 ? null : Name;
                    var fields = reader.AcroFields.Fields;
                    var RequestID = reader.AcroFields.GetField("requestId");
                    CultureInfo MyCultureInfo = new CultureInfo("en-US");
                    var OpenDate = reader.AcroFields.GetField("openDate");
                    DateTime? OpenDate2 = null;
                    try
                    {
                        OpenDate2 = DateTime.ParseExact(OpenDate, "d/M/yyyy h:mm", MyCultureInfo);
                    }
                    catch
                    {
                        OpenDate2 = null;
                    }
                    var Org = reader.AcroFields.GetField("organization");
                    DateTime? NeedDate = Convert.ToDateTime(reader.AcroFields.GetField("needDate"));
                    var FirstName = reader.AcroFields.GetField("firstName");
                    var LastName = reader.AcroFields.GetField("lastName");
                    var Email = reader.AcroFields.GetField("email");
                    var Phone = reader.AcroFields.GetField("phone");
                           
                    DateTime StartDate = Convert.ToDateTime(reader.AcroFields.GetField("startDate"));
                    DateTime EndDate = Convert.ToDateTime(reader.AcroFields.GetField("endDate"));
                    var Notes = reader.AcroFields.GetField("notes");
                    //var signature = reader.AcroFields.GetField("Signature");

Open in new window


I need to set a variable for signature to the Signature field in my form.  It is coming thru as blank.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Task Lead
Commented:
I figured this out myself:

 var sig = reader.AcroFields.VerifySignature("Signature").SignName;
DateTime? sigDate = Convert.ToDateTime(reader.AcroFields.VerifySignature("Signature").SignDate);

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial