PDF Editing Issues

Fix Acrobat JavaScript Unterminated String Errors in PDF Forms

Maira MehtabMaira Mehtab Nov 18, 2026 868 views

Question details

The user needs to add a line break to text generated by an Acrobat form script without causing a JavaScript syntax error.

Fix Acrobat JavaScript Unterminated String Errors in PDF Forms
Product
Adobe Acrobat
Device & OS
not provided
Scenario
A PDF form script assigns text containing a line break to a text field.
Observed behavior
An actual line break inside a quoted JavaScript string produces a SyntaxError: unterminated string literal.
Before you start

Locate the form field and the script that sets its value. Check whether the text field has enough height to display more than one line.

Solution 1Recommended

Use an escape sequence and enable multiline text

Use this method when the form field needs to display text on separate lines.

1
Open the field properties

In Acrobat, open the PDF and choose Prepare a form. Select the text field, then open its Properties.

2
Edit the script

Open the field's existing JavaScript from the relevant tab, such as Calculate > Custom calculation script > Edit. Replace the actual line break inside the quoted string with \r, for example: event.value = "Instructional text goes here,\rnext paragraph";

3
Enable multiline display

In the field Properties, select the Options tab and enable Multi-line. Adjust the field height if needed, then close Properties.

4
Test the form

Exit form editing or use Preview, then trigger the script and confirm that the text appears on separate lines without a syntax error.

Use an escape sequence and enable multiline text
Keep the escape sequence inside the string: Type the backslash and letter r as \r; do not press Enter between the quotation marks. The example uses event.value in a field script that sets the field's value.
Free Microsoft Office alternative

Work with PDFs and Office files in WPS Office

WPS Office is a free, lightweight alternative with a familiar interface for working with Office files and PDFs. It can help you move between document formats, but it does not repair Acrobat form JavaScript errors.

View PDFs and access PDF editing tools in the same applicationCompatible with Microsoft Office formats including DOCX, XLSX, and PPTXMove existing Office documents into a familiar, easy-to-use workspaceUse a lightweight office suite with a free version
microsoft office alternative - wps office

Frequently Asked Questions

Why does pressing Enter inside the quoted string cause an error?

A regular JavaScript string enclosed in single or double quotation marks cannot contain an unescaped actual line break. Replace it with an escape sequence such as \r.

Why does the text still appear on one line after I add \r?

Open the field Properties in Prepare a form, select Options, and enable Multi-line. Also check that the field is tall enough to show multiple lines.

Where can I find the field's calculation script?

In Acrobat, choose Prepare a form, open the field's Properties, and check Calculate > Custom calculation script > Edit. If the script is attached elsewhere, open it from its existing location instead.

Can I avoid using a line-break escape sequence?

Yes. If the text does not need a new line, remove the actual line break from the quoted string and use a space between the sentences.