Free Support Forum - aspose.com

Getting Started - Need to capture form fields example

I need an example of how this works. Looks like the problem is editing the pdf with form fields is not saveable to file. The pdf is sent out to end users, when they have edited/submitted I want a copy of that pdf so I can scrape the data out of it. How is this done? The end users won’t have acrobat to save a edited pdf. I was hoping to not have to write a website to handle this feature. Ideally I’d email the pdf and they would create an email and send it back with the filled in data attached. The private back end system can review/consume and scrape the data in house without having to create a public facing website. There is a 3rd party in the middle as in, wholesaler - broker - customer.


To test, I start with a blank pdf, programatically add a text field and submit button. But then how can I scrape the field data out of an edited pdf done by a user outside of the system? I created one test to create the pdf and then I show it and manually use adobe reader to try to save it to my harddrive in the temp dir, but then when I go to read it back up the data isn’t there.

#region Test003CreatePDFToEdit
[NUnit.Framework.Test]
public void Test003CreatePDFToEdit()
{
AsposeTotalLicense license = new AsposeTotalLicense();
Aspose.Pdf.Kit.License asposeLicense = new Aspose.Pdf.Kit.License();
asposeLicense.SetLicense(license.GetLicense());

string sourcePDF = “C:\Code\Skywalker\Tests\TestsNUnit\Templates\Blank.pdf”;
string destinationPDF = System.IO.Path.Combine(System.IO.Path.GetTempPath(), “Test003CreatePDFToEdit.pdf”);
string submitPDF = System.IO.Path.Combine(System.IO.Path.GetTempPath(), “Test003CreatePDFToEdit.pdf”);

Aspose.Pdf.Kit.FormEditor formEditor = new Aspose.Pdf.Kit.FormEditor(sourcePDF, destinationPDF);

Aspose.Pdf.Kit.FormFieldFacade facade = new Aspose.Pdf.Kit.FormFieldFacade();
formEditor.Facade = facade;
facade.BackgroudColor = System.Drawing.Color.FromArgb(240, 240, 255);
facade.BorderStyle = Aspose.Pdf.Kit.FormFieldFacade.BorderStyleBeveled;
formEditor.AddField(Aspose.Pdf.Kit.FieldType.Text, “Text1”, “”, 1, 200, 550, 300, 575);

formEditor.AddField(Aspose.Pdf.Kit.FieldType.PushButton, “Submit1”, “OK”, 1, 265, 695, 365, 720);

formEditor.ResetFacade();
formEditor.Save();

formEditor.SetSubmitUrl(“Submit1”, submitPDF);

formEditor.Save();
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo = new System.Diagnostics.ProcessStartInfo(destinationPDF);
process.Start();

while (!process.HasExited)
{
System.Windows.Forms.Application.DoEvents();

System.Threading.Thread.Sleep(500);
}
}
#endregion
#region Test004LoadEditedPDF
[NUnit.Framework.Test]
public void Test004LoadEditedPDF()
{
AsposeTotalLicense license = new AsposeTotalLicense();
Aspose.Pdf.Kit.License asposeLicense = new Aspose.Pdf.Kit.License();
asposeLicense.SetLicense(license.GetLicense());

string submitPDF = System.IO.Path.Combine(System.IO.Path.GetTempPath(), “Test003CreatePDFToEdit.pdf”);

Aspose.Pdf.Kit.Form form = new Aspose.Pdf.Kit.Form(submitPDF);

string value = form.GetField(“Text1”);

NUnit.Framework.Assert.AreEqual(“XYZ”, value);
}
#endregion

Hello James,

Thanks for using our products.

We are working over this query and will get back to you soon. We apologize for the delay and inconvenience.

Hi James,

Once you have created the PDF form fields and get it filled manually from your customers etc., you can export the PDF form data to XML file and then use the data from the XML. Please see the following help topic for an example: Import and Export to XML.

The submit button option can only be used if you want to send the PDF form data to a web page and then manipulate the data using your web application. Please see the following help topic: Posting AcroForm data to External Web Page.

Please see if this helps in your scenario. If you find any further questions, please do let us know.
Regards,