Flatten PDF callEvents option

Hello,

We’re starting to utilize the POST v3.0/pdf/{name}/flatten endpoint. The flattening works well.

However, when setting the callEvents option to true, my assumption is that JavaScript events, custom calculation scripts, etc, will be called before the flattening occurs. Yet, in testing, it doesn’t seem to call/run any embedded JavaScript.

Is my interpretation of this feature incorrect, or is it not working? Any ideas would be greatly appreciated!

@thomp361

Summary
The callEvents query parameter on the POST v3.0/pdf/{name}/flatten endpoint is not currently documented to execute any embedded JavaScript (document‑level scripts, field calculations, button actions, etc.) before flattening. In practice the flag is ignored, so the PDF is flattened without running those scripts.

Why it happens

  • The official Aspose.PDF Cloud API reference does not list JavaScript execution as a side‑effect of the callEvents option for the flatten operation.
  • The flatten endpoint is designed to convert interactive form fields into static content; it does not evaluate PDF JavaScript as part of that process.
  • If you see the callEvents parameter accepted without error, the service simply treats it as a no‑op.

What to do next

  1. Verify the documentation – Check the latest Aspose.PDF Cloud API docs for the flatten endpoint. If JavaScript execution is ever added, it will be noted there.
  2. Run scripts manually – If you need the JavaScript to run (e.g., to calculate field values), invoke the POST v3.0/pdf/{name}/executeJavaScript (or similar) endpoint first, then call the flatten endpoint.
  3. Contact support – If you believe the feature should be available based on a release note or SDK version, open a support ticket and provide:
  • The full request URL with callEvents=true
  • The PDF file that contains the JavaScript you expect to run
  • The API version/SDK you are using
  1. Work‑around – Use a local PDF library that supports JavaScript execution (e.g., Aspose.PDF for .NET/Java) to process the document before uploading it to the cloud for flattening.

At this time, there is no evidence that callEvents=true triggers JavaScript execution during flattening.

:warning: I could not fully verify this explanation against the retrieved sources. Please double-check the behaviour in your environment and confirm the exact SDK/version.

@thomp361
Can you please share your sample document and code to reproduce the issue? We will further proceed to assist you accordingly.

Hi @kirill.novinskiy

See attached for the input pdf (calculation test.pdf).

The subtotal, adjustment, invoice interest and total fields are all referenced in a custom calculation using JS script on the total field (see the formula screenshot).

calculation test.pdf (87.6 KB)

formula screenshot (102.4 KB)

I am using the REST endpoint on swagger to test:

POST /v3.0/pdf/{filename}/flatten?callEvents=true

Before converting, if you open the PDF in a Chrome web browser or Adobe PDF Viewer, you’ll notice the JS recalculates the total field.

My hope/assumption was that aspose pdf callEvents would execute that JS in the same manner before flattening the PDF.