Calculation & Validation via Javascript

I found ONLYOFFICE a few days ago, and so far, I’m very pleased with the feature set. However, my primary function is to create .pdf forms and most of them involve some kind of calculation or validation via Javascript (per Adobe standards). I’m not seeing a method for attaching these scripts in the ONLYOFFICE .pdf creator. Is there something obvious I’m missing, or is that part of the standard not implemented?

I noticed a couple of prior posts on the subject of calculated fields, but they are from 2022 and 2023, so I decided to start a fresh thread.

I’m using the desktop version of ONLYOFFICE on Linux Mint at home and on Windows 10 at work.

Hey @dlstein, :wave:

Thanks for your kind words about ONLYOFFICE and for sharing your use case with PDF forms! I’m glad you’re enjoying the feature set. Regarding your question about calculations and validations via JavaScript in PDF forms (per Adobe standards), you’re right that this is a specific area, and I appreciate you starting a fresh thread.

You might find this recent article from our blog helpful:
How to perform calculations on specific fields in a PDF form using an ONLYOFFICE macro.

However, if you’re looking for direct JavaScript integration for calculations/validations in PDF forms (as supported in Adobe Acrobat), this isn’t natively implemented in ONLYOFFICE yet. Our PDF editor supports form creation and basic field interactions, but Adobe-style JavaScript for dynamic calculations or validations is not fully supported.

Could you provide more details about the specific JavaScript functionality you’re aiming for compared to Adobe?
This would help us understand your needs better and see if macros can bridge the gap or if we need to log this as a feature request.

Thanks for your input, and I’ll keep you posted! :wink:

Good afternoon, I apologize for taking so long to get back to you. I create a variety of forms, generally to support clerical or programming/project development. Some are quite complicated.

The JS falls into two general areas for me: field calculation and entry validation.

One example for a multi-page form with a header, detail lines and a footer:

Standard “Page XX of YY” - I use a validation script to ensure Page_XX isn’t greater than Page_YY.

In the header there are two field containing strings to identify system properties, I’ll call them “Sys_Type” and “Sys_Level”. The user selects these from a dropdown box.

There are 32 detail lines (for example), and the labels are filled (read only) with a calculation script because if Page_XX == 1, the line numbers are 1-32, whereas, if Page_XX == 2, the line numbers are 33-64. If Page_XX == 3, the line numbers are 65-96, and so on.

The elements on the line include a description and a field name, which are simple entry boxes with input limits.

The next field is selected from a combo box I’ll call “DataType”, for which the options are “C”, “D”, “L” and “N”. The next field in the row is called “Data_Size” calculated as such:

Data_Type is evaluated to determine if it is fixed length or variable length. Types “C” and “N” turn read-only off for Data_Size and leaves that field blank for the user to enter a value. Types “D” and “L” store 8 and 1 (respectively) to Data_Size and Make it read-only.

The next column in the body is for decimal positions, and only applies if Data_Type is “N”, otherwise the formula that calculates Data_Size set it read-only.

The header counts the number of lines for which the size is not blank and adds that column to create a “number of fields” and “total record size” field.

This is a really simplified overview, as I’ve skipped a few columns and the calculation for field length also depends upon the selections made in “Sys_Type” and “Sys_Level” in the header.

I understand ONLYOFFICE has some macro functionality. Am I correct in assuming that wouldn’t work for a user with a different .pdf viewer? I distribute these forms to users on several platforms, and with the Javascript calculations, they can be used in Adobe products, or in browsers, LibreOffice or other office suites.

Thanks,
Dylan

Hey @dlstein, :wave:

Thanks for the thorough breakdown of your PDF form workflow — that’s exactly the kind of detail that helps us grasp the complexity. It’s clear why Adobe-style JavaScript is crucial for your cross-platform distribution, and you’re spot on that macros in ONLYOFFICE wouldn’t translate to other viewers like Adobe or LibreOffice.

To better understand and explore potential workarounds (or log this as a feature request), could you share a sample PDF file with some of those implemented scripts? Even a simplified version would be awesome. Alternatively, a short video demo of the form in action (e.g., filling fields and seeing calculations/validations trigger) would be super helpful for a quick visual — it’d benefit other users too, as they could skim it for ideas.

You can upload to Google Drive or kDrive and drop the link here.
Appreciate your insights!

The short answer is yes. I’ll remove any proprietary information from one and upload it. I’m on vacation until next Tuesday, so I’ll attend to it when I get back into the office.

1 Like