PDF Editing Issues

Remove Empty Lines from a Calculated Adobe Acrobat Form Field

Aamir Naveed AkramAamir Naveed Akram Nov 19, 2026 868 views

Question details

Remove blank lines automatically from a calculated PDF form field when source fields are empty.

Remove Empty Lines from a Calculated Adobe Acrobat Form Field
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.
Before you start

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.

Solution 1Recommended

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.

1
Open the summary field

In Acrobat, open the PDF and select Prepare a form. Double-click the Summary of Services field to open its Properties.

2
Edit the calculation script

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");

3
Test the calculation

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.

Join only nonempty fields in the Acrobat calculation script
Multiline source fields: This script skips empty source fields but preserves line breaks already inside a nonempty source field.
Free Microsoft Office alternative

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.

Open and work with PDF documents alongside office filesCompatible with Microsoft Office formats such as DOCX, XLSX, and PPTXFamiliar interface for a smoother move from Microsoft OfficeFree, lightweight tools for everyday document tasks
microsoft office alternative - wps office

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.