How to Print PDF Form Fields on Specific Pages Using JavaScript
Question details
The user needs to print specific form fields only on designated pages while keeping them hidden on other pages during the printing process.

- Product
- Device & OS
- not provided
- Scenario
- Using JavaScript to dynamically control the visibility of form fields during a multi-page PDF print job.
- Observed behavior
- Setting fields to 'noPrint' permanently prevents them from printing on any page, requiring visibility to be dynamically managed via scripts triggered during the print action.
Ensure you have access to a PDF editor that supports JavaScript execution and form field management, and back up your original PDF document before applying custom scripts.
Control Form Field Visibility with JavaScript Print Parameters
Use JavaScript to temporarily hide fields for the first batch of pages, print them, unhide the fields, and print the remaining pages.
Since setting a field to 'noPrint' affects the entire document, you need to execute a script that changes the 'display' property of the fields before and after printing specific page ranges.
Page numbers in PDF JavaScript are zero-based, meaning page 1 is index 0.
Open your PDF editor and navigate to the Form or JavaScript tools to add a document-level script or create a custom print button.
Set your target fields to hidden using the script: getField('FieldName').display = display.hidden;
Call the print function for pages 1 and 2 using zero-based indexing: this.print({bUI: false, nStart: 0, nEnd: 1});
Set the fields back to visible (display.visible) and print the third page: this.print({bUI: false, nStart: 2, nEnd: 2});
Assign Unique Field Names for Easier Property Management
If fields are duplicated across pages, give them unique names so you can assign different printing properties to each without complex scripting.
Edit and Print PDF Forms Easily with WPS Office
WPS Office provides a comprehensive PDF toolkit that allows you to easily manage form fields, edit document content, and customize print settings. Whether you need to fill out forms or print specific sections, WPS Office makes it seamless.
- 1. Open your PDF in WPS Office: Launch WPS Office and open the PDF document containing the form fields.
- 2. Access the Form tools: Navigate to the 'Form' tab to view, edit, or adjust the properties of your form fields.
- 3. Customize Print Settings: Go to 'Menu' > 'Print' to specify page ranges and choose whether to print the document with or without form fields.

Frequently Asked Questions
Why does setting a field to 'noPrint' hide it on all pages?
The 'noPrint' property is applied to the form field object itself. If a field spans multiple pages or the setting is applied globally, it will prevent the field from printing anywhere in the document.
What does zero-based page numbering mean in PDF JavaScript?
Zero-based numbering means the index starts at 0 instead of 1. Therefore, page 1 is referenced as nStart: 0, page 2 is 1, and page 3 is nStart: 2.
Can I trigger this JavaScript automatically when the user clicks 'Print'?
Yes, you can add your script to the 'Will Print' document action. However, intercepting and splitting print jobs via the standard print dialog can be complex, so it is often easier to create a custom 'Print' button on the form that executes the script.




