We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Read Form Fields in PDF and fill them using Aspose.PDF for .NET - “Field Not Found” exception

Hi,


I am using Aspose PDF to access (fill) fields in a PDF form created by in LiveCycle ES4. However, when I call GetFieldType on the field names (as listed in the attribute FieldNames on the Aspose.Pdf.Facades.Form object), I get a “Field Not Found” exception.

The call to FillField works (with the same name that fails on GetFieldType).

Can you please tell me the correct way to refer to a field in an ES4 document. I also tried using the call to GetFullFieldName, but that just returned the value passed in, in all cases.

GetFieldType did appear to work with earlier versions of pdf generation tools.

Lastly, the ES4 documents do have custom names for the forms. (For example, the PDF Form name is “StudentForm”. ) Is there anything special that needs to be done because of that? Forms on past documents were not specifically named, and were just using the defaults.

Thanks!
Karen
Hi Karen,

Thanks for using our API.

Please share the resource file, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Thanks for such a quick reply.


I have attached 3 files, that all illustrate the same issue.

“LC ES4 custom form name.pdf” and “LC ES4 Generic form name.pdf” have multiple fields. The call to fill the fields (FillField) works, but the call to GetFieldType fails. (With the “Field not found” exception)

I have also attached a file “LC ES4 Text Field Only.pdf”, which has only one field on it (at text field). This file also illustrates the same issue.

Please let me know if you need any other information. Thanks very much for your help!

Karen

Hi Karen,


Thanks for sharing the resource files.

Can you please share your code snippet as I am unable to replicate the issue when using my sample code.

Hi Nayyer,


Here is some code that illustrates the issue. It is C#.


// this is the path to the file. can be any of example files sent in earlier reply, or any file created in LiveCycle ES 4
string sLocalPath = “C:\AsposeTest\TestForm.pdf”;
Form asposeForm = new Form(sLocalPath);

// asposeForm.FieldNames[0] is: “form1[0].#subform[0].TextField1[0]” in the generic pdf, “LC ES4 generic form name.pdf”
// it is “JohnsForm[0].SubForm1[0].TextField1[0]” in “LC ES4 custom form name.pdf”
string sFirstFieldName = asposeForm.FieldNames[0];

try
{
FieldType fieldType = asposeForm.GetFieldType(sFirstFieldName); // this throws an error
}
catch(Exception ex)
{
// the error will be “Field not found”
string sErrorMessage = ex.Message;
}

// Fill field (with the same field name), works in all cases.
// in this example, the FillField call is expecting to set the value of a textbox
string sValue = “Anythingworks”;
asposeForm.FillField(sFirstFieldName, sValue);


Thanks!
Karen

Hi Karen,


Thank for sharing the code snippet and sorry for the delayed response.

I have tested the scenario and have observed that ArgumentException is being generated when trying to fill data inside LC+ES4+TEXT+FIELD+ONLY.pdf and its a different error than what you have stated above. However I am working on testing the scenario with other two files and will get back to you soon.

Hi Karen,


Thanks for your patience.

I
have tested the scenario and I am able to reproduce the same problem (field not found error being generated when calling GetFieldType(…) method). For the
sake of correction, I have logged it in our issue tracking system as
PDFNEWNET-39222. We
will investigate this issue in details and will keep you updated on the status
of a correction.

We apologize for your inconvenience.

Hi Nayyer,


Thanks so much for your help. Yes, I should have been more clear that it is an ArgumentException->Field Not Found error. I am glad you sorted it out! Thanks!

Do you have any timeframe when we might know any more from Aspose? Is there any other way besides GetFieldType to find out the type of a field in a document?

Thanks for everything,
Karen

Hi Karen,

Thanks for your feedback.

KarenEhret:

Thanks so much for your help. Yes, I should have been more clear that it is an ArgumentException->Field Not Found error. I am glad you sorted it out! Thanks!


Thanks for the for acknowledgment.

KarenEhret:

Do you have any timeframe when we might know any more from Aspose? Is there any other way besides GetFieldType to find out the type of a field in a document?


As we have recently noticed the issue and it is pending for the investigation in queue with other issues, reported earlier. I am afraid we can not share any ETA before completion of the analysis. We will notify you as soon as we made some significant progress towards issue resolution.

We are sorry for the inconvenience caused.

Best Regards,

Thanks so much for the detailed response. I understand how it is hard to provide any ETA.


I also wanted to verify that there is no other way to find out the type of a field on a pdf? Specifically, I need to know if it is a checkbox or not, so that I can call the correct “fillField” method. Is there any other way to know this?

Thanks so much. I very much appreciate your assistance.

Karen

Hi Karen,


Thanks for your inquiry. We are looking into an alternate way to find form field type of XFA(dynamic) form. We will update you our findings asap.

Best Regards,

Hi Tilal,


May I ask if you have any updates on this issue? It is very pressing for us.

Yes, as you say, the issue seems to be related to the XFA forms. From that, it sounds like you have been able to reproduce well internally, but if there is anything I can do, or any other information you need from me, please let me know.

Thanks for your work on this!

Best Regards,
Karen



KarenEhret:
May I ask if you have any updates on this issue? It is very pressing for us.
Hi Karen,

Thanks for your patience.

As we recently have been able to notice the issue, so its still pending for review. As soon as we have some definite updates, we will let you know.

KarenEhret:
Yes, as you say, the issue seems to be related to the XFA forms. From that, it sounds like you have been able to reproduce well internally, but if there is anything I can do, or any other information you need from me, please let me know.
Surely if any information is required, we will let you know.

Thanks again!

We have also noticed that the call to “GetButtonOptionValues” (and maybe some other calls) does not work with the Dynamic Forms, created in LiveCycle ES4. (It works fine with documents created in other tools, including ES2)


Support of these LiveCycle documents is crucial for us, so any progress/insight/workarounds would be very much appreciated.

Best Regards,
Karen

Hi Karen,


Thanks for sharing the feedback.

The information is associated with the issue reported earlier and as soon as we have some further updates, we will let you know.

Hi Karen,


Thanks for your patience. GetFieldType() method works for AcroForm (Standard) forms only. For XFA (Dynamic) forms, Field template XML should be analyzed as following. Hopefully it will help you to accomplish the task.

Document doc = new
Document(“LC+ES4+TEXT+FIELD+ONLY.pdf”);<o:p></o:p>

string[] fields = doc.Form.XFA.FieldNames;

foreach (string field in fields)

{

XmlNode node = doc.Form.XFA.GetFieldTemplate(field);

if (node.Name == "field")

{

Console.WriteLine(node.Attributes["name"].Value + " " + node.ChildNodes[0].ChildNodes[0].Name);

}

else if (node.Name == "exclGroup")

{

Console.WriteLine(node.Attributes["name"].Value + " " + "RadioButton");

}

}

Please feel free to contact us for any further assistance.


Best Regards,