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);