Multiple form fields with same key cannot be filled

Hi there,

I recently got tasked with filling a PDF template from the IHK which can be found here: muster-berufsausbildungsvertrag-pdf-data.pdf

However, using aspose-pdf-23.4-jdk17 and the following code:

					if(field instanceof TextBoxField)
					{
						
						String fieldValue = getFormFieldValue(field, data);
						Ivy.log().debug("Setting TextBoxField with Key: {0} to {1}", field.getFullName(), fieldValue);
						
						TextBoxField tbf = (TextBoxField) field;
					
						if(fieldValue != null)
						{
							tbf.setValue(fieldValue);
							tbf.setReadOnly(true);
						}
						continue;
					}

I am not seeing any value in e.g. Auszubildenden E-Mail-Adresse or Auszubildenden Mobil- oder Telefonnummer although it acquired a non-null value by getFormFieldValue() - nor are they readonly.

Another thing which doesn’t seem to work is the value of the fields Auszubildenden Name, Auszubildenden Vorname and so on - the values are visible on the third page, however, if I click on them in pdf.js, the values are gone when editing - and they are not readonly either.

The fields were acquired by com.aspose.pdf.Field[] fields = doc.getForm().getFields(); other than that, we just save it by:

doc.save(outputFile);

My vague guess is that Aspose does not like a key (?) to appear multiple times in the same PDF Form - the filling process however works well in PDF.js or Acrobat Reader, therefore I am really lost here.

Is this a known limitation of Aspose.PDF or am I doing something wrong here?

@maio290

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFJAVA-44531

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

1 Like

Thanks for that!

I also did some additional research today using the trial version of Adobe Acrobat and found out that the form looks pretty ordinary as expected within Adobe’s stuff - when I look at the form fields in Acrobat, I see those with multiple appearances suffixed with #{idx} whereas Aspose doesn’t seem to be able to acquire this which might be the issue, but I know next to nothing about the internal workings of a PDF file.

The fields also have a parent with the same name (e.g. Auszubildenden Name) but when I try to set either contents or value on the parent, I am getting the following exception:

java.lang.NullPointerException: Cannot invoke "com.aspose.pdf.IDocument.getForm()" because "this.ld" is null
	at IvyProjectClassLoader [pmv=designer$DocFactory$1,generation=2]//com.aspose.pdf.Annotation.getAppearance(Unknown Source)
	at IvyProjectClassLoader [pmv=designer$DocFactory$1,generation=2]//com.aspose.pdf.WidgetAnnotation.lI(Unknown Source)
	at IvyProjectClassLoader [pmv=designer$DocFactory$1,generation=2]//com.aspose.pdf.WidgetAnnotation.lI(Unknown Source)
	at IvyProjectClassLoader [pmv=designer$DocFactory$1,generation=2]//com.aspose.pdf.Annotation.setContents(Unknown Source)
	at IvyProjectClassLoader [pmv=designer$Onboarding$1,generation=58]//de.xxx.service.ContractService.renderPDFTemplate(ContractService.java:400)

The fastest workaround is probably to modifiy the keys to make them independent in Acrobat, I tried this in Aspose but this didn’t make a difference when I added a partial name to every form field.

@maio290

Thanks for sharing your findings. We have updated the ticket information accordingly and will surely inform you once we make some progress towards its resolution. Please be patient and spare us some time. We are sorry for the inconvenience.