PDF Editing Issues

How to Concatenate Variables and Strings in PDF JavaScript

Phi Hung VoPhi Hung Vo Nov 24, 2026 869 views

Question details

The user needs to know how to properly combine variables and strings in PDF form JavaScript without triggering syntax errors.

How to Concatenate Variables and Strings in PDF JavaScript
Product
Adobe Acrobat PDF
Device & OS
not provided
Scenario
Writing custom JavaScript calculations or actions for interactive PDF forms.
Observed behavior
Using modern ES6 template literals (backticks) or keywords like 'const' causes syntax errors in legacy PDF JavaScript engines.
Before you start

Before modifying your form scripts, ensure you have access to a PDF editor that supports form field JavaScript editing, and back up your original PDF file.

Solution 1Recommended

Use the Standard String Concatenation Operator (+)

Replace ES6 template literals with the traditional plus operator for maximum compatibility across all PDF readers.

Many PDF readers utilize legacy JavaScript engines that do not support modern ES6 syntaxes, such as template literals (backticks) or block-scoped variables ('let' and 'const').

By replacing these modern elements with traditional JavaScript syntax, you ensure your PDF form calculations and text generation work seamlessly across all viewers.

1
Open PDF Form Properties

Open your interactive PDF form in edit mode and right-click the specific form field to access its Properties.

2
Navigate to the Scripting Section

Locate the tab where your custom JavaScript is executed, such as the Calculate tab or a specific Mouse Up action trigger.

3
Modify Variable Declarations

Change any modern ES6 variable declarations like 'const' or 'let' to the older 'var' keyword. For example, write: var cARm = 5;

4
Replace Backticks with Quotes and Plus Signs

Remove ES6 backtick template literals. Replace them with standard quotes and the plus (+) operator. For example, instead of `${cARm} mL-removed`, write: var removed = cARm + ' mL-removed';

5
Save and Test

Click OK to save the script, then test the form field to ensure the strings and variables concatenate properly without throwing syntax errors.

Use the Standard String Concatenation Operator (+)
Best Practice for PDF Scripts: Using standard 'var' declarations and '+' concatenation guarantees your interactive PDF remains fully functional even when opened in older or third-party PDF readers.
Advanced PDF Management

Edit and Manage PDF Forms Seamlessly with WPS Office

WPS Office provides a comprehensive PDF editor that allows you to easily view, fill, and manage interactive PDF forms without dealing with complex software configurations.

  1. 1. Download and Install WPS Office: Get the free WPS Office suite from the official website and install it on your computer.
  2. 2. Open Your PDF File: Launch WPS PDF and open the interactive form you need to manage or fill out.
  3. 3. Edit or Fill the Form: Use the PDF editing and form tools to input data, manage your document content, and save your progress effortlessly.
Easily edit PDF text, images, and interactive formsHighly compatible with standard PDF formats and older document typesLightweight application with a familiar, intuitive user interface
microsoft office alternative - wps office

Frequently Asked Questions

Why do template literals (backticks) cause errors in PDF forms?

Many PDF readers use older, legacy JavaScript engines that were developed before modern ES6 standards were introduced. As a result, they do not recognize syntax like template literals or the 'const' keyword, resulting in script failures.

Can I use 'let' or 'const' in PDF JavaScript?

It is highly recommended to use 'var' instead of 'let' or 'const'. Using 'var' ensures maximum compatibility across various PDF readers, especially those built on older software frameworks.

How do I test my PDF JavaScript for syntax errors?

You can open the built-in JavaScript console in advanced PDF editors (often accessible via Ctrl+J or Cmd+J) to view detailed syntax errors or runtime exceptions when interacting with form fields.