Remove Empty Lines from a Calculated Adobe Acrobat Form Field
Question details
Remove blank lines automatically from a calculated PDF form field when source fields are empty.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A Summary of Services field combines several form field values with line breaks.
- Observed behavior
- Empty source fields still contribute newline characters, leaving blank lines in the calculated summary.
Open the PDF in Adobe Acrobat and identify the exact names of the source fields and the calculated summary field. Check that the summary field is set up to use a custom calculation script.
Join only nonempty fields in the Acrobat calculation script
Use this approach to prevent empty source fields from adding blank lines to the summary.
The script collects values that contain at least one non-whitespace character, then joins them with a single newline. Replace the example field names with the names in your form.
In Acrobat, open the PDF and select Prepare a form. Double-click the Summary of Services field to open its Properties.
Select the Calculate tab, choose Custom calculation script, and click Edit. Replace the existing concatenation code with: var names = ["Service1", "Service2", "Service3"]; var values = []; for (var i = 0; i < names.length; i++) { var field = this.getField(names[i]); if (field) { var value = field.valueAsString; if (/\S/.test(value)) values.push(value); } } event.value = values.join("\n");
Save the script and close Properties. Enter values in some source fields, leave others empty, and check that the summary contains no extra lines between those values.

Use WPS Office for Everyday PDF and Document Work
WPS Office is a free, lightweight alternative with a familiar interface for everyday PDF and Office document work. Its format support makes it easy to move common files between applications. Edit and test Acrobat-specific calculation scripts in Acrobat.

Frequently Asked Questions
Why does my calculated field show blank lines?
Adding a newline after every source field also adds one for empty fields. Collect only nonempty values and use join("\n") to put line breaks between them.
Where do I edit the calculation script in Acrobat?
Open Prepare a form, double-click the calculated field, and go to Calculate. Select Custom calculation script and click Edit.
Will the script remove blank lines inside a source field?
No. It skips source fields that are empty or contain only whitespace, but it preserves the contents of nonempty fields, including their internal line breaks.
What should I check if the summary does not update?
Verify the source field names in the script and check Acrobat's JavaScript preferences. If source fields are also calculated, review their order using the field calculation order option in Prepare a form.




