PDF Editing Issues

How to Calculate GST in PDF Forms Using JavaScript

Tauseeq MagsiTauseeq Magsi Nov 3, 2026 869 views

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.

How to Calculate GST in PDF Forms Using JavaScript
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.
Before you start

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.

Solution 1Recommended

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.

1
Open Field Properties

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'.

2
Navigate to the Calculate Tab

In the Properties dialog box, click on the 'Calculate' tab.

3
Add Custom Calculation Script

Select the 'Custom calculation script' radio button, then click the 'Edit' button next to it.

4
Enter the GST Script

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.

5
Calculate the Final Total

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 Decimal Tax Rate
Check Field Names: Ensure the names inside the getField() parentheses exactly match your actual form field names. JavaScript is case-sensitive.
Complete PDF Solution

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. 1. Open WPS PDF: Launch WPS Office and open your fillable PDF form using the WPS PDF tool.
  2. 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. 3. Save and Share: Once the calculations are complete, securely save your PDF or directly share it with your clients or colleagues.
Easily interact with and fill out calculated PDF formsSeamlessly edit text, images, and pages in your PDF documentsFully compatible with standard interactive PDF formats including Adobe Acrobat filesLightweight, fast-loading, and incredibly easy to use across your devices
QA img-9

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.