XFA initialize JavaScript events do not fire after Save

When I load a dynamic XFA PDF and immediately save it using Aspose, all embedded JavaScript events (initialize, calculate, click, etc.) stop working in Adobe Acrobat — even if I do not modify the document. It leads to some broken attachment functionality.

Aspose.PDF version: 25.6.1.0 (.Net)

Code:

using (var document = new Aspose.Pdf.Document("Original.pdf"))
{
    document.Save("Result.pdf");
}

Files:
Original.pdf (315.6 KB)
Result.pdf (335.9 KB)

@ayershovmgb

Cause

The issue you’re experiencing with JavaScript events in dynamic XFA PDFs not firing after saving with Aspose.PDF is likely due to how the library handles XFA forms. When you save the document, it may alter the structure or properties of the XFA form, leading to the loss of JavaScript functionality.

Solution

To retain JavaScript functionality after saving, you can try the following approach:

  1. Use the IgnoreNeedsRendering property: This property allows you to bypass certain rendering requirements that may affect JavaScript execution.

  2. Convert XFA to AcroForm: If your use case allows, consider converting the XFA form to a standard AcroForm, which may help maintain JavaScript functionality.

Here’s how you can implement these solutions in your code:

Code

using (var document = new Aspose.Pdf.Document("Original.pdf"))
{
    // Check if the document has XFA and if rendering should be ignored
    if (document.Form.HasXfa)
    {
        document.Form.IgnoreNeedsRendering = true; // Bypass rendering requirements
    }

    // Optionally convert to AcroForm if needed
    document.Form.Type = Aspose.Pdf.Forms.FormType.Standard;

    // Save the PDF document
    document.Save("Result.pdf");
}

Next Steps

  1. Test the above code to see if it resolves the issue with JavaScript events.
  2. If the problem persists, check the specific JavaScript code in your PDF to ensure compatibility with the changes made by Aspose.PDF.
  3. If you continue to experience issues, please provide more details about the JavaScript events and their expected behavior.

Please implement these solutions, and let me know if you need further assistance!

I’ve tried all those recommendations but am still facing the same issue.
JavaScript populates some attachment details from XML with elements on the page. It also opens the attachments when a user clicks the “View” button.

@ayershovmgb

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): PDFNET-60219

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.