Filling XFA form fields using C#

Hi,

I am trying to fill XFA form fields using the following code. However after running the code, the value is not being set to the field and it sets a blank value:

var license = new License();
license.SetLicense(@"Aspose.Pdf.lic");
Aspose.Pdf.Facades.Form pdfForm = new Aspose.Pdf.Facades.Form();
pdfForm.BindPdf(new MemoryStream(Resource1.TSYS_Profit_Center_Form_04192017));
pdfForm.Document.Form.XFA["EMV"] = "No";
pdfForm.Save("output.pdf");


Please find the PDF file with XFA Form attached.

Please let us know how to fill XFA form fields using Aspose.

Thank you

Hi Kyle,

Thanks for contacting support.

In order to fill XFA field, you need to provide its complete name. Please take a look over following code snippet. For your reference, I have also attached the output file generated over my end.

[C#]

// Load XFA form

Document doc = new Document("c:/pdftest/TSYS%2bProfit%2bCenter%2bForm%2b04192017+(5).pdf");
// Get names of XFA form fields
string[] names = doc.Form.XFA.FieldNames;
//for (int counter = 0; counter <= names.Length; counter++)
{
    // Console.WriteLine(names[counter]);
}

// fill the dropdown field titled "Will you be using this processor for Debit processing?"
doc.Form.XFA["form1[0].#subform[0].sub1[0].use_debit[0]"] = "No";

// save the PDF file
doc.Save("c:/pdftest/Filled_XFA_output.pdf");