Hello - I am using PDF.Kit.Form to merge my data with form fields in a PDF. In some cases the PDF contains multiple fields with the same field name. When I merge a PDF with 2 or more fields with the same name, only one of the duplicate named field gets populated with data.
I checked the XML source of the PDF and it is only the first field occurance that gets populated. I verified this by swapping the XML of two fields with duplicate names and the first field always gets populated while the second does not. All other fields that do not have duplicates receive the data OK.
I have tried doing this merge with Form.ImportXml() as well as Form.Fill(). The same result happens with both methods. I was using PDF.Kit v 2.7.0.0. I tried using the latest v.3.3.0.0 and the issue still remains.
I have attached a sample PDF that demonstrates this issue. Please look for the two “LastName” fields. Thanks in advance for your help.
Update: As an alternative to the Form class I tried the AutoFiller class (ImportDataTable function) and the same issue happens with this method as well.
Hi,
Thank you very much for considering Aspose.
We're looking into the matter and will update you the earliest possible.
We appreciate your patience.
Regards,
Hi,
We have investigated the issue at our end and realized that two fields with the same name can't be added in a pdf file. Can you please elaborate the issue in a bit more detail? Also, if you could share related xml files as well, that'll help us understand and resolve the issue.
Regards,
From my experience Adobe does not complain when saving two field names with the same name. If you please take a look at the PDF document i attached in my first post you can see that there are two fields with the same field name “LastName”. Can you confirm this?
I forgot to attach the XML in the first post. You can find it attached here. Please notice the two “LastName” fields at the top of the document. This matches the PDF i attached in the first post. Thank you for your help
Hi,
Thanks for sharing the resource files. We are looking into the details of this problem and will reply to you soon.
Hi,
I’ve tested the scenario and have noticed that, “multi-test.pdf” does not get populated when using ImportXml()
method. I’ve tried importing the data contents of “multi-test.xml” that you have shared, but no success. I’ve used the following code snippet.
//Assign input and output PDF documents
Aspose.Pdf.Kit.Form form = new Aspose.Pdf.Kit.Form(@"c:\Temp\multi-test.pdf", @"c:\Temp\multi-test_filled.pdf");
//Create an XML file as a FileStream that contains the contents of the PDF document
System.IO.FileStream xmlInputStream = new System.IO.FileStream(@"c:\Temp\multi-test.xml", System.IO.FileMode.Open);
//Import the values from the XML file to the PDF form
form.ImportXml(xmlInputStream);
//Save the output PDF document
form.Save();
//Close the input XML stream
xmlInputStream.Close();
It would be more appropriate if you could share the code snippet that you are using.
During my investigation, I’ve found that, the two occurrences of LastName field, are present as LastName[0]
and LastName[1].
When you simply call the method Form.Fillfield("LastName","Mike")
, it searches for the field named as “LastName” and fills in the information for the first instance which is LastName[0]. But, if you try using the following code snippet, you would notice that, both the field occurrences get filled.
//Instantiating Aspose.Pdf.Kit.Form object giving input and output PDF files as input
Aspose.Pdf.Kit.Form form = new Aspose.Pdf.Kit.Form(@"c:\Temp\multi-test.pdf", @"c:\Temp\multi-test_filled.pdf");
//Filling a Text Field (Name)
form.FillField("LastName[1]","Mike");
form.FillField("LastName[0]","Mike");
//Save the output PDF document
form.Save();
The exact full name of the field can be something like topmostSubform[0].Page1[0].LastName[0] or topmostSubform[0].Page1[0].LastName[1]. Please visit the following link for information on Identifying form fields names.
If it does not satisfy your query, please feel free to contact
Hi Nayyer,
Thank you for your detailed response and help with this problem. After reading your response I must clarify a few things. First of all the XML i sent you is not the XML i am using to load the PDF Form object. I copied that XML out of the XML view in Adobe LiveCycle Designer. I am loading the PDF Form object from the actual PDF file, not from Form.ImportXML() as you suggested. I have no problems opening the PDF using the PDF file that is attached in my first post. With that said, I now have a second issue with another PDF. I will clarify both remaining issues below:
Issue #1 (from above)
From your response I now understand that we are using the term “Field Name” differently. When you say FieldName you are referring to the full field name in Form.FieldsNames - i.e. “topmostSubform[0].Page5[0].LastName[0]”. When I was referring to field name i meant the “short” field name like you would see in Adobe - i.e. “LastName”. I would like to fill all fields named “LastName” with a value regardless of what form or page they are on and regardless if there are multiple fields with that name on the same page and form. I want all of them filled with the same value. I would like to be able to run Form.FillField(“LastName”, “test”); and have all instances of that field filled. Is this possible or is this not possible?
Issue #2 (new)
Now I am having a new, but related, issue with another PDF. Please see the PDF attached to this post. This PDF contains three LastName fields. I am trying to fill each field with the full field name. Please consider the code below.
pdf.FillField(“topmostSubform[0].Page5[0].LastName[0]”, “test”);
pdf.FillField(“topmostSubform[0].Page6[0].LastName[1]”, “test”);
pdf.FillField(“topmostSubform[0].Page6[0].LastName[0]”, “test”);
If you use the above code with the attached PDF only the first two “LastName” fields get filled. In order to futher debug this issue I tried commenting out all but one of these three lines - in other words filling only one of them. If i run that first line of code by itself, it fills the first field as expected. If i run the second line by itself it fills the second field as expected. If i run the third line by itself it fills the first field instead of the expected third field. As you can see they have completely different full field names specified yet the wrong field is getting filled. Please let me know if you can reproduce this behavior with this PDF.
Thank you for your help.
Hi,
Please spare us little time, as we are looking into the details of this problem and will reply to you soon.
Dear Ruiz ,
Thanks for considering Aspose.Pdf.Kit.
This problem has been reproduced at our platform. It has been recorded into our bug tracing system. We are working hard to solve this problem, the ETA is about 3 weeks. Thanks for your patience.
Best regards.
Luke, thank you for the update. I look forward to hearing the results.
Hi Luke, is there any news on this issue?
Dear Ruiz ,
Thanks for your patience. This issue is ongoing as we planned before. The reason has been found and we are studying how to solve it. The fixed is expected to be included in the next release. Once finished it, I will inform you here.
Best regards.
Dear Ruiz,
Sorry for the late notification. This issue has been solved and after careful testing, the hotfix will be included in the next release. Please notice our blog for the information.
Best regards.
Hi Lukeyoyo,
We have tried this latest release and it is still not filling all fields with the same name. We have noticed that sometimes it will fill the first two fields with the same name, but it will not fill unlimited fields with the same name.
Please take a look at the attached PDF. There are 4 “FirstName” fields. When we fill “FirstName” only the first, maybe the second field get filled and the remaining first name fields are left empty. The same thing happens with the 4 “LastName” fields.
Please let me know if this can be resolved. Thank you
Dear Ruiz,
I noticed that this problem is the same one as <A href="https://forum.aspose.com/t/123174</A>. Actually this problem has been solved. However, from technical reason, this issue was not included in the newest version. But it is sure to be included in the next release. And if you need this feature urgently, please contact us, a trail version can be provided for your test in advance.</P> <P>Thanks for your patience & Best regards.</P>
Hi Luke,
Isn’t that link the same thread we are speaking in now? Yes this is urgent for us. Please send the version for testing.
Dear Ruiz,
Sorry for my ridiculous mistake :P
I have contacted our Product Manager, he will provide you a trial version soon. Please try it.
Best regards.
Hi,
The issue has been resolved, please download the attached beta version 3.4.2.3 and try it before we publish a new version.
Thanks,