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.

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.


This Topic is created by codewarior using the Email to Topic plugin.

@bamundson,

Thanks for your patience.

We have further investigated earlier reported PDFJAVA-34250 and in order to generate Static forms, following code snippet should be used:
[C#]

Document doc = new Document("c:/pdftest/Test_11.pdf");
doc.getForm().getXFA().set_Item("form1[0].#subform[0].OrderedByName[0]", "Aspose Pdf for Java");
doc.save("c:/pdftest/Filled_Test_11_out.pdf");

Furthermore, these forms can be converted to standard form and edited with the code:

Document pdfDocument = new Document("c:/pdftest/Test_11.pdf");
com.aspose.pdf.Form form = pdfDocument.getForm();
form.setType(FormType.Standard);

TextBoxField textBoxField = (TextBoxField) form.get("form1[0].#subform[0].Header[0].OrderedByName[0]");
textBoxField.setValue("Pdf version 17.5");
pdfDocument.save(myDir+"outputForm.pdf");

Please try using latest release version of Aspose.Pdf for Java 17.5 and in case you encounter any issue, please feel free to contact.