We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Execute JavaScript in form field Format or Calculate tab


We’re using the Java version of Aspose.Pdf. We have some existing PDF documents that we are populating with data. A number of fields utilize JavaScript for either “Custom Format Script” or “Custom calculation script”. formField.recalculate() doesn’t appear to do anything at all. I can do the following:

pdfDocument.setOpenAction(new JavascriptAction(“this.calculateNow();”));

But naturally that will only run when the document gets opened in Acrobat or Reader. I would like to get Aspose to output the PDF with the calculated values so that opening the document is not required. Some of these PDFs go directly to another piece of software that parses them so if the document hasn’t been opened the values will not yet be there.

I hope that makes sense. Let me know if you have any questions. Have a great day!



Thank you for contacting support.

Please note that Aspose.PDF for Java API mimics the behavior of Adobe Acrobat so we are afraid that any action or event may not launch until that operation takes place. Please feel free to let us know if you can figure out an approach with Adobe Acrobat so that we may investigate further to help you out.

Are you saying that if I save the document with a setOpenAction() applied to it, and then reopen the document with Aspose, that the JavaScript and calculations will run? We want to keep Acrobat out of the picture if possible and rely on Aspose to populate all data and run any field calculations.

Actions aside, is there any other way to allow the Format or Calculate JavaScript to run within Aspose?


When a PDF document is loaded into Document Object Model (DOM) of Aspose.PDF for Java API then Document actions are not launched as they occur with different PDF readers, so the JavaScript and calculations will not run in this case. Moreover, we have logged an investigation ticket with ID PDFJAVA-38192 in our issue management system for further investigations. We will let you know as soon as some further updates will be available.