I used the code from your link to discover what the field names are in the pdf document my customer provided. I don't think the field names were supplied. Because of that, the field names seem to be automatically generated, for example the first field name shows up as:
form1[0].#subform[0].TextField1[0]
This is what allfields[i] returns from the code below ( sample code from your website). I tried to access that field using:
form.FillField("form1[0].#subform[0].TextField1[0]", "1234");
But I'm getting an "object reference not set" exception. I also tried to rename that field by doing:
editor.RenameField(allfields[i], "Item" + i);
but I'm getting the same exception. So if the field names are not set in the pdf document, how can I populate these fields with values?
thanks,
//First a input pdf file should be assigned
Aspose.Pdf.Kit.Form form = new Aspose.Pdf.Kit.Form(@"c:\pdftest\FilledForm.pdf");
//get all field names
String[] allfields = form.FieldsNames;
// Create an array which will hold the location coordinates of Form fields
System.Drawing.Rectangle[] box = new System.Drawing.Rectangle[allfields.Length];
for (int i = 0; i < allfields.Length; i++)
{
// Get the appearance attributes of each field, consequtively
FormFieldFacade facade = form.GetFieldFacade(allfields[i]);
//Box in FormFieldFacade class holds field's location.
box[i] = facade.Box;
}
form.Save();
// Now we need to add a textfield just upon the original one
FormEditor editor = new FormEditor(@"c:\pdftest\FilledForm.pdf", @"c:\pdftest\new_test_form_updated.pdf");
for (int i = 0; i < allfields.Length; i++)
{
// add text field beneath every existing form field
editor.AddField(FieldType.Text, "TextField" + i, allfields[i], 1, box[i].Left, box[i].Top, box[i].Left + 50, box[i].Top + 10);
}
//Close the document
editor.Save();