Convert Currency Amounts to Words in Acrobat Forms with JavaScript
Question details
Create an Acrobat form that converts numeric amounts to words according to the selected currency, and learn how to rotate a stamp with JavaScript.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form contains an amount and a currency selector, and its author wants a calculated field to display the amount in words.
- Observed behavior
- The desired output uses the conversion function for the selected currency, such as USD, EUR, or UAH, while a stamp annotation can be created with a specified rotation.
In Acrobat, check the exact names of the amount, currency, and output fields and make sure the currency choices have the expected export values. Prepare or obtain a number-to-words function for each currency; Acrobat does not provide the functions shown below automatically.
Calculate the amount in words from the selected currency
Use a custom calculation script when the output must change with the amount or currency selection.
The example assumes fields named Amount and Currency, with currency export values USD, EUR, and UAH. It also assumes document-level functions named EnUS, EU, and UA already exist and return the desired text, including any currency units and fractional amounts.
Open the JavaScript tools in Acrobat and add your EnUS, EU, and UA functions as document-level JavaScripts. Implement the wording and rounding rules needed for each currency.
Open Prepare a Form, select the field that should display the words, and open Properties. On the Calculate tab, choose Custom calculation script and click Edit.
Enter this script, adjusting field and function names to match your form: var amount = this.getField("Amount").valueAsString; var currency = this.getField("Currency").valueAsString; var val = Number(amount); event.value = ""; if (amount !== "" && isFinite(val)) { if (currency === "USD" && typeof EnUS === "function") event.value = EnUS(val); else if (currency === "EUR" && typeof EU === "function") event.value = EU(val); else if (currency === "UAH" && typeof UA === "function") event.value = UA(val); }
Close the form editor, enter a plain numeric value in Amount, and select each option in Currency. Confirm that the output field recalculates and that the wording and fractional units are correct.

Rotate a stamp annotation with Acrobat JavaScript
Use the rotate property when creating a stamp annotation programmatically.
Work with PDF Forms and Office Files in WPS Office
WPS Office is a free, lightweight, easy-to-use Office alternative with a familiar interface and support for common Office formats, making it easier to move existing documents. For Acrobat-specific form JavaScript and stamp scripting, use Acrobat to create and test the scripts.

Frequently Asked Questions
Where do I put the currency conversion script in Acrobat?
In Prepare a Form, open the words-output field's Properties, select Calculate, and edit its custom calculation script. Put the reusable conversion functions in document-level JavaScripts.
Why is the calculated words field blank?
Check that Amount and Currency match the actual field names, that the currency export value matches the script, and that the corresponding conversion function exists. Also check that the amount is a numeric value the script can parse.
Does the sample script define the USD, EUR, and UAH wording rules?
No. EnUS, EU, and UA are example function names. You must provide functions that return the wording, currency units, and fractional amounts required for your form.
How do I change the rotation of a stamp created by addAnnot?
Set the rotate property in the addAnnot options to an integer number of degrees, such as rotate: 5, and inspect the resulting stamp on the page.
Will the form calculation work in every PDF viewer?
Not necessarily. PDF viewers differ in their support for Acrobat JavaScript and form calculations. Test the form in each viewer your recipients will use.




