How to Calculate GST in PDF Forms Using JavaScript
Question details
The user needs to add a JavaScript formula to a PDF form to automatically calculate the Goods and Services Tax (GST) based on a selling price and tax rate, as well as compute the final total.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- Creating or modifying a fillable PDF form that requires automated tax and total price calculations.
- Observed behavior
- The user wants the PDF form fields to automatically output the calculated GST and the final total price when the selling price and tax rate are manually entered.
Ensure that you have already created the necessary text fields in your PDF form and named them exactly as they will appear in your script (e.g., 'SalesPrice' and 'SalesTax') before adding the custom calculation.
Calculate GST Using a Decimal Tax Rate
Use this method if your tax rate field expects users to input the rate as a decimal (for example, entering 0.05 to represent a 5% tax).
PDF forms can perform automated calculations using custom JavaScript. By retrieving the values inputted into the SalesPrice and SalesTax fields, you can compute the tax amount and total dynamically.
Open your PDF form in edit mode. Right-click or double-click the text field where you want the calculated GST to appear, and select 'Properties'.
In the Properties dialog box, click on the 'Calculate' tab.
Select the 'Custom calculation script' radio button, then click the 'Edit' button next to it.
Type the following code into the JavaScript editor: var price = Number(this.getField("SalesPrice").value); var tax = Number(this.getField("SalesTax").value); event.value = price * tax; Then click OK.
To calculate the final total including GST in a separate field, repeat the process for the Total field and use this script instead: event.value = price + (price * tax);

Calculate GST Using a Whole Number Percentage
Apply this adjusted script if your tax rate field expects users to enter a whole number for the percentage (such as entering 5 to represent 5%).
Easily Manage Fillable PDF Forms with WPS Office
WPS Office provides a comprehensive PDF editor that allows you to open, fill, and manage interactive PDF forms seamlessly. Whether you are dealing with invoices, tax forms, or business contracts, WPS PDF makes document handling highly efficient.
- 1. Open WPS PDF: Launch WPS Office and open your fillable PDF form using the WPS PDF tool.
- 2. Interact with Forms: Navigate through your document. Fillable fields will be highlighted, allowing you to enter numbers and trigger any built-in calculations.
- 3. Save and Share: Once the calculations are complete, securely save your PDF or directly share it with your clients or colleagues.

Frequently Asked Questions
Why is my PDF form calculation returning a zero?
This usually happens if the field names referenced in your JavaScript do not exactly match the actual names of your text fields. Check for typos, capitalization, and extra spaces in field names like 'SalesPrice' and 'SalesTax'.
Can I use basic mathematical operators instead of custom JavaScript for PDF forms?
Yes. In the field properties under the Calculate tab, you can select 'Value is the [sum/product] of the following fields' for simple addition or multiplication. However, computing a percentage calculation involving two fields generally requires a custom script.
How do I format the final calculated total as currency?
To display the calculated GST or total as currency, open the Field Properties, go to the 'Format' tab, select 'Number' or 'Custom', and choose your preferred currency symbol and decimal places (usually 2).
Will this JavaScript calculation work on all PDF readers?
While custom JavaScript calculations function perfectly in full-featured PDF editors like Adobe Acrobat and advanced desktop PDF tools, some basic mobile PDF viewers or built-in web browser viewers might not support interactive JavaScript executions.




