How to Remove Blank Spaces When Hiding PDF Form Fields
Question details
The user wants to eliminate the empty layout gaps that remain when optional PDF form fields are hidden.

- Product
- PDF Editors
- Device & OS
- not provided
- Scenario
- Creating an interactive PDF form where certain form fields can be toggled to hidden, requiring the layout to adjust dynamically.
- Observed behavior
- Hiding a field makes it invisible but leaves a blank space on the page instead of automatically repositioning the remaining fields to close the gap.
Before modifying your form field properties, ensure you have a backup copy of your original PDF form and basic familiarity with using JavaScript in PDF forms.
Use JavaScript to Dynamically Reposition Remaining Form Fields
Since standard PDFs use a fixed layout, you must use a custom JavaScript action to manually recalculate and update the bounding box (the rect property) of the visible fields.
In standard PDF forms, hiding a field does not trigger an automatic reflow of the document like it would in HTML. To eliminate the blank space, you must write a script that detects when a field is hidden and actively changes the coordinates of the fields below it to shift them upwards.
Right-click the form field that controls the visibility (e.g., a checkbox or a dropdown) and select 'Properties'.
Navigate to the 'Actions' tab. Select 'Run a JavaScript' from the 'Select Action' dropdown menu and click 'Add'.
In the JavaScript Editor, write a script that triggers on change. Use 'this.getField("TargetFieldName").rect' to get the current coordinates of the fields positioned below the hidden one. Adjust the Y-coordinates in the array to move the field up, then assign the new array back to the field's 'rect' property.
Save the script and return to the form filling mode. Toggle your checkbox to ensure the fields shift correctly. Verify that the dynamic movement has not disrupted the logical tab order of your document.

Use a Dynamic Form Designer (like AEM Forms)
If coding JavaScript for multiple shifting fields becomes too complex, use an XML-based dynamic form creator like Adobe Experience Manager (AEM) Forms Designer.
Edit and Organize PDF Form Fields in WPS Office
If you prefer a more straightforward way to build and manage static PDF forms without writing complex JavaScript, WPS Office provides an intuitive form-building suite. You can quickly add, delete, and perfectly align fields manually.
- 1. Open your PDF in WPS Office: Launch WPS Office and open the PDF form you wish to modify.
- 2. Navigate to the Form tab: Click on the 'Form' tab in the top ribbon to access the interactive form tools.
- 3. Adjust field layouts manually: Select the fields that are leaving blank spaces. You can quickly drag and drop the fields to close any gaps manually.
- 4. Align fields: Select multiple fields and use the alignment tools in the properties panel to ensure they are evenly spaced and perfectly aligned.

Frequently Asked Questions
Why do blank spaces appear when I hide a PDF form field?
Standard PDF files use a fixed coordinate system for layout. When you set a form field to be invisible, the software simply stops rendering it, but it does not automatically collapse the layout or reflow the remaining elements like a web page would.
Can I remove the blank space without using JavaScript?
In standard AcroForm PDFs, no. The fixed layout requires JavaScript to dynamically shift the remaining fields. To avoid JavaScript entirely, you would need to recreate the form using an XML-based dynamic form creator like AEM Forms Designer (formerly LiveCycle Designer) which supports automatic 'flowed' layouts.
What is the rect property in PDF JavaScript?
The 'rect' property is an array of four numbers that defines the bounding box (coordinates and size) of a form field on the page. By modifying these four numbers via JavaScript, you can programmatically move a field or change its dimensions.
Will repositioning fields via JavaScript affect user experience?
It can. Dynamically moving fields might impact the visual flow or the document's tab order. It is crucial to test your form thoroughly after applying JavaScript to ensure users can still tab through the fields logically.




