Fix Acrobat JavaScript Unterminated String Errors in PDF Forms
Question details
The user needs to add a line break to text generated by an Acrobat form script without causing a JavaScript syntax error.

- 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.
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.
Use an escape sequence and enable multiline text
Use this method when the form field needs to display text on separate lines.
In Acrobat, open the PDF and choose Prepare a form. Select the text field, then open its Properties.
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";
In the field Properties, select the Options tab and enable Multi-line. Adjust the field height if needed, then close Properties.
Exit form editing or use Preview, then trigger the script and confirm that the text appears on separate lines without a syntax error.

Keep the field text on one line
Use this simpler option when a new paragraph is not necessary.
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.

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.




