开发者

Capture filled PDF form data

I would like to capture 开发者_如何学Gofilled PDF form data from public facing website and save it in the database on the server. Is it possible?Please let me know.


Yes, it is possible. You need a submit button on the form. In the properties of the submit button, select FDF as data type. Each field from the PDF document will have a name. Textbox1, Textbox2, etc. and you will receive name-value pairs. There are libraries available that will assist with processing the returned data.

I received the completed PDF document in my Controller (ASP.NET MVC application) as follows:

string filename = Path.Combine(Server.MapPath(rootPath), name);
using (FileStream fs = new FileStream(filename, FileMode.CreateNew))
{
    byte[] bytes = new byte[8192];
    int bytesRead;
    while ((bytesRead = Request.InputStream.Read(bytes, 0, bytes.Length)) > 0)
    {
        fs.Write(bytes, 0, bytesRead);
    }
}

In this case filename is a temporary filename located in a temp area (rootPath) where I have write access. Another solution will be to write the file to a MemoryStream and then use that to send in email.


I would recommend looking into one of the PDF libraries such as iTextSharp. This entry will show you how to loop through all of the form fields in a PDF. And this entry will show you how to get fields by a given name.


You can use FDFToolkit.net to save PDF form submissions to a database:

http://www.fdftoolkit.net

Here's an example with ASP.net(VB.net), ADO.net, and SQL:

If Not IsPostBack Then
    Dim fdfApp As New FDFApp.FDFApp_Class()
    Dim fdfDoc As New FDFApp.FDFDoc_Class()
    fdfDoc = fdfApp.FDFOpenFromStream(Request.InputStream, True, True)
    Dim dr As DataRow
    Dim ds As New DataSet
    Dim da As New System.Data.SqlClient.SqlDataAdapter("SELECT * FROM TABLENAME", "CONNECTION STRING")
    da.Fill(ds, "TABLENAME")
    dr = ds.Tables(0).NewRow
    'SET VALUES THAT MATCH NAMES IN TABLE & IN PDF
    'fdfDoc.FDFSetDataRowFromValues(dr)
    dr("FIELD_NAME1") = fdfDoc.FDFGetValue("PDF_FIELD_NAME1")
    dr("FIELD_NAME2") = fdfDoc.FDFGetValue("PDF_FIELD_NAME2")
    ' DUMP XML FILE TO FIELD
    dr("FIELD_DUMP_XML") = fdfDoc.FDFSavetoStr(FDFDoc_Class.FDFType.XML, True)
    ds.Tables(0).Rows.Add(dr)
    da.Update(ds, "TABLENAME")
    fdfDoc.FDFClose()
    fdfDoc.Dispose()
End If


To automatically send the filled data via e-mail you can do the following:

  1. Add a PDF Button ("Submit")
  2. Right-click -> PDF Options -> Field Properties
  3. Select "Action" Tab
  4. Select the Submit Form type
  5. in the url type mailto:mail.recipient@anymail.com
  6. In the submit format select FDF or the format you want

DONE!

When the user clicks it, it will automatically attach the datafile to the email. It will ask the user whether to use default email or webmail.

The FDF file you receive or any other format, will have to be parsed in order to extract the data.

I know this is old, but someone might be looking for this answer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜