PDF generation using XDP loosing Java script functionality in PDF | Community
Skip to main content
Level 2
April 30, 2025
Solved

PDF generation using XDP loosing Java script functionality in PDF

  • April 30, 2025
  • 1 reply
  • 1573 views

We are using XDP file and XML files to generate the PDF document.  We have check boxes in the PDF  and javascript included in the XDP file.  It is loosing the check box functionality in generated PDF.

 

 Code Snippet

 

 var file  = new java.io.File(templateFolder, pdfTemplate);
var inDoc = new com.adobe.aemfd.docmanager.Document(new java.io.FileInputStream(file));
 
    var xmlDoc = new com.adobe.aemfd.docmanager.Document(xmlDataPart.getInputStream());
var xciDoc = new com.adobe.aemfd.docmanager.Document(xciTemp);
 
    var pdfOptions  = new com.adobe.fd.output.api.PDFOutputOptions();
//Set PDF properties using XCI template
    pdfOptions.setXci(xciDoc);
 
    //Flatten PDF
    var outputService = sling.getService(Packages.com.adobe.fd.output.api.OutputService);
    var result = outputService.generatePDFOutput(inDoc, xmlDoc, pdfOptions);
This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Pranay_M

Hi @manjulako,

I can see that you are using the output service for generating the PDF. I can understand that you have some code which is executing when you click the checkboxes. However, please note that when using the output service to merge the XML with XDP, it is only designed to merge the data into the XDP and generate the PDF with the filled data. Having said that when you pass both the XML and XDP though the output service it only executes the events on the "Initialize event" and the "calculate event". If you have the scripts written on any other events it will not execute the same.

 

To resolve the problem, please move your code from the specific event to the calculate event and your issue should be resolved.

 

Thanks
Pranay

1 reply

Pranay_MAdobe EmployeeAccepted solution
Adobe Employee
April 30, 2025

Hi @manjulako,

I can see that you are using the output service for generating the PDF. I can understand that you have some code which is executing when you click the checkboxes. However, please note that when using the output service to merge the XML with XDP, it is only designed to merge the data into the XDP and generate the PDF with the filled data. Having said that when you pass both the XML and XDP though the output service it only executes the events on the "Initialize event" and the "calculate event". If you have the scripts written on any other events it will not execute the same.

 

To resolve the problem, please move your code from the specific event to the calculate event and your issue should be resolved.

 

Thanks
Pranay

ManjulaKoAuthor
Level 2
April 30, 2025

Thanks Pranay. I do have Events in the XDP file. Do we need to move these events code into the XML file? 

 

<event name="event__click" activity="click">
<script contentType="application/x-javascript">

form1.Page1_SP.presence = "visible";

xfa.host.currentPage = 0;
</script>

 

 Do I need to use <event name="event__click" activity="calculate">   instead of click?

Adobe Employee
April 30, 2025

Hi @manjulako,

You don't need to move the events to XML. Instead, as you mentioned, currently, you have the script written on the click event. You will need to move the code logic to calculate the event so that it is triggered at runtime.
In your XML you can simply pass the value for the checkbox as true or false and on the calculate event you just need to add a "if..else" block which checks if the checkbox is selected or not and then perform the specific action.

Thanks
Pranay