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

Free Support Forum - aspose.com

Writing to Adobe version 9-X-XI Static Form Fields

Hi,
In evaluating your product (aspose-pdf-9.1 for java), I am conducting various compatibility tests with a number of different versions of Adobe forms. I have a few different static PDF forms that I am trying to set the value on a TextBoxField, and save the resulting PDF. I am trying to do so using the following code (taken from here: http://www.aspose.com/docs/display/pdfjava/Modify+Form+Field+in+a+PDF+Document):

com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document(“test.pdf”);

//I can verify the “some.path.to.field” exists as I am using the Field getFullName() method once
//I call Field[] fields = pdfDocument.getForm().getFields()
WidgetAnnotation anno = pdfDocument.getForm().get(“some.path.to.field”);

if(anno instanceof com.aspose.pdf.TextBoxField){
((com.aspose.pdf.TextBoxField)anno).setValue(“shouldBeEdited”);
((com.aspose.pdf.TextBoxField)anno).setReadOnly(true);
}
pdfDocument.save(“test_edited.pdf”);

Now this works fine for my PDFs that are:
PDF Version: 1.6 (Acrobat 7.x)
PDF Version: 1.7 (Acrobat 8.x)

The new field values are never written for my PDFs that are:
PDF Version: 1.7 Adobe Extension Level 3(Acrobat 9.x)
PDF Version: 1.7 Adobe Extension Level 8(Acrobat X)
PDF Version: 1.7 Adobe Extension Level 11(Acrobat XI)

Is it possible to set form field values using the code above with any forms that are Acrobat 9.x and above? Or can I only use the XFA data to set the value of these fields that are Acrobat 9.x and above? This would prove difficult as the Acrobat X and Acrobat XI Forms I am testing with have to XFA Fields. Thank you.

Hi Brian,

Thanks for your inquiry. Aspose.Pdf support to fill XFA fields, please check following sample code. However, we will appreciate if you please share a sample PDF form of each problematic version. So we will test the scenario and will provide you information accordingly.

Document doc = new Document(myDir + "inputform.pdf");
doc.getForm().getXFA().set_Item("form1[0].#subform[0].Name[0]", "Aspose Pdf for Java");
doc.save(myDir + "inputform_out.pdf");

We are sorry for the inconvenience caused.

Best Regards,

Hi,

Thank you for the quick reply. I am uploading 3 PDFs

PDF Version: 1.7 Adobe Extension Level 3(Acrobat 9.x)
PDF Version: 1.7 Adobe Extension Level 8(Acrobat X)
PDF Version: 1.7 Adobe Extension Level 11(Acrobat XI)

Each of which I cannot successfully set the fields using the code specified earlier. These PDFs were created with Adobe LifeCycle Designer ES4, directly from a sample template, and saved as Static PDFs with 3 different compatibility versions. I did not edit these sample PDFs in any way. I can successfully read the values of Fields using:

Field[] fields = pdfDocument.getForm().getFields();
String someValue = fields[someIndex].getValue();

But no luck setting values and saving them. Thank you.

Hi Brian,


Thanks for sharing your source PDF forms. We have tested these and found that 1.7 Adobe Extension Level 3(Acrobat 9.x) contains XFA fields and can be filled using XFA from properties as suggested above. However we have replicated the reported issue with other two form and logged it as PDFNEWJAVA-34250 for further investigation and will keep you updated about the issue resolution progress.

Document doc = new Document(myDir

  • “Test_09.pdf”);<o:p></o:p>

doc.getForm().getXFA().set_Item("form1[0].#subform[0].OrderedByName[0]", "Aspose Pdf for Java");

doc.save(myDir + "Test_09_out.pdf");


Please feel free to contact us for any further assistance.


Best Regards,

Thank you for the response. I do have more information in regards to the fields not being populated. When reviewing the 3 Documents (9, X, and XI) after I have tried to update the fields I did notice something else.


When looking at the edited documents in Adobe Reader XI, the fields appear as they are not filled in. But if I open the document in directly through my FireFox browser, the fields ARE populated as per my edits.

Any idea why Adobe Reader would not display the proper field values, but other PDF viewers would? This is still a stopper for me, as most, if not all of our clients would use Adobe Reader. Thank you.

Just incase anyone else has this issue, I have figured out what the issue was. After trying a whole bunch of things, if you make a call to a field’s flatten() method, before you call the field’s setValue() method, the new field values will properly display in Adobe Reader.

Unfortunately flattening the field to get the text to appear in Adobe Reader, will prevent the field from being read from the document, since it is completely removed. So in essence, flattening the field does not solve my problem.



Hi Brian,


Thanks for sharing the details. We are working over this query and will get back to you soon.
bamundson:
Just incase anyone else has this issue, I have figured out what the issue was. After trying a whole bunch of things, if you make a call to a field's flatten() method, before you call the field's setValue() method, the new field values will properly display in Adobe Reader.
Hi Brian,

Thanks for your patience and sorry for the delayed response.

When calling Flatten() method, it Removes all fields from the document and place their values instead. Since the form fields are removed, so you are able to view the values when opening the document in Adobe Reader.

bamundson:
Thank you for the response. I do have more information in regards to the fields not being populated. When reviewing the 3 Documents (9, X, and XI) after I have tried to update the fields I did notice something else.

When looking at the edited documents in Adobe Reader XI, the fields appear as they are not filled in. But if I open the document in directly through my FireFox browser, the fields ARE populated as per my edits.

Any idea why Adobe Reader would not display the proper field values, but other PDF viewers would? This is still a stopper for me, as most, if not all of our clients would use Adobe Reader. Thank you.

Hi Brian,

I have tested the scenario using Aspose.Pdf for Java 9.1.0, where I have tired filling all the PDF forms (Test_9.pdf, Test_10.pdf and Test_11.pdf) using following code snippet and as per my observations, the form fields are properly being filled and I am able to see the values in resultant files when viewing the output in Adobe Reader 9.X and Adobe Reader 11.0.3.

[Java]

Document doc = new Document(“c:/pdftest/Test_11.pdf”);<o:p></o:p>

doc.getForm().getXFA().set_Item("form1[0].#subform[0].OrderedByName[0]", "Aspose Pdf for Java");

doc.save("c:/pdftest/Filled_Test_11_out.pdf");


For your reference, I have attached the output PDF files (filled forms) generated over my end.