Import FDF into PDF in C# using Aspose.PDF - Javascript is not being executed

We have FDF’s that we are merging into PDF’s then saving them as PDF. It all works well, except javascript is not being executed. The javascript in question is not event based - it should automatically run always to concatenate fields in the document.

Can you please explain how I can get the javascript to fire?

The output from the Aspose test shows as ‘undefined undefined undefined’ whereas when opening in PDF it works.

//-------------------------------------------------------------
//-----------------Do not edit the XML tags--------------------
//-------------------------------------------------------------

//<AcroForm>
//<ACRO_source>ConcatenateCarrierAddress:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:ConcatenateCarrierAddress:Calculate ***********/
var a = this.getField("CAR12").valueAsString;
var b = this.getField("CAR12_1").valueAsString;

var f = "\r";

event.value = a + "   " + b;

//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>ConcatenateCarrierCityStateZip:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:ConcatenateCarrierCityStateZip:Calculate ***********/
var a = this.getField("CAR13").valueAsString;
var b = this.getField("CAR14").valueAsString;
var c = this.getField("CAR15").valueAsString;


var f = "\r";

event.value = a + "  " + b+ "  " + c;

//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Concatenate_INSURED_UNIT_MAIL_1:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Concatenate_INSURED_UNIT_MAIL_1:Calculate ***********/
var a = this.getField("IU2").valueAsString;
var b = this.getField("IU2_1").valueAsString;

var f = "\r";

event.value = a + "   " + b;
//</ACRO_script>
//</AcroForm>

//<AcroForm>
//<ACRO_source>Concatenate_INSURED_UNIT_MAIL_2:Calculate</ACRO_source>
//<ACRO_script>
/*********** belongs to: AcroForm:Concatenate_INSURED_UNIT_MAIL_2:Calculate ***********/
var value3 = this.getField("IU5").valueAsString;
var value4 = this.getField("INU5_1").valueAsString;
if (value4 == "") {
event.value = value3
}
else {
event.value = value3 + "-" + value4
}
//</ACRO_script>
//</AcroForm>

The code I am using to process the FDF’s is:

Aspose.Pdf.Facades.Form form = new Aspose.Pdf.Facades.Form();
form.BindPdf($"{sourceDirectory}\\{pdfName}");
System.IO.FileStream fdfInputStream = new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read);

form.ImportFdf(fdfInputStream);
                
fdfInputStream.Close();
PdfViewer viewer = new PdfViewer();
form.Save(outFile);

@JohnHennesey

Thanks for contacting support.

There is no method which can be used to execute Javascript while importing FDF into PDF document. However, would you kindly share your source FDF file along with respective source PDF document. We will test the scenario in our environment and address it accordingly. Also, please share your expected PDF document as well.

Please see attached.

Aspose FDF test.zip (1.1 MB)

@JohnHennesey

Could you please also share how can we check if Javascript is working in your expected output PDF? We tried to change values in Numeric fields but it did not reflect any modification to other fields. Would you please share the steps to verify and compare the output with one generated by Aspose.PDF.

The javascript concatenates the addresses. Compare the (expected) file with the output from the code - you will see the (expected) file will have a full concatenated address, whereas the output from the aspose code will have ‘undefined’ listed many times.

@JohnHennesey

We were able to replicate the issue in our environment and have logged it as PDFNET-47524 in our issue tracking system for the sake of correction. We will surely look into details of it and keep you posted with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

Good afternoon asad.ali -
Do you have any kind of an update on this?

@JohnHennesey

We regret to share that issue has not been resolved due to low priority. As it was logged under free support model, it will resolved on first come first serve basis. We will surely inform you as soon as we have some certain news on it resolution. Please spare us some time.

We are sorry for the inconvenience.

We just refreshed our license so we can have this looked at faster. How can we transfer this ticket over to the paid support model?

@JohnHennesey

You may please create a post in paid support forum with reference to the ticket ID and your issue priority would be updated accordingly.

Any movement on this? How long does it usually take to resolve tickets under the free support model?

@JohnHennesey

The resolution time of the issue depends upon nature of it i.e. its complexity, the components of API which needs to be investigated, features and enhancements need to be added to fix the it. The earlier logged ticket is not yet resolved sadly. However, we will share with you as soon as we have some certain news about its resolution. Please spare us some time.

We are sorry for the inconvenience.