How to Print Only PDF Form Pages That Contain User Data
Question details
The user wants to print a multi-page PDF form, ensuring required pages are always printed, but optional pages are only printed if their associated fields contain user data.

- Product
- Device & OS
- not provided
- Scenario
- Printing a long PDF form containing optional sections to avoid wasting paper on completely blank form pages.
- Observed behavior
- The user needs a way to dynamically evaluate which optional fields have data and adjust the document's print range accordingly before sending it to the printer.
Ensure you are using a PDF editor that supports JavaScript execution and that you know the exact field names and page numbers (0-indexed) for the optional sections of your form.
Use JavaScript to Dynamically Set the Print Range
Create a custom print script that checks the value of specific form fields and builds an array of pages to print.
By utilizing the Acrobat JavaScript API within your PDF editor, you can script a custom print button that analyzes field values. If an optional field is not empty, its corresponding page is added to the print queue.
Open the JavaScript console or the action settings of your custom print button. Start by getting the default print parameters using `var pp = this.getPrintParams();`.
Create an empty array to hold the page ranges you want to print, for example, `var printArray = [];`. Push your required page arrays into this list first.
Use `this.getField("YourFieldName").valueAsString` to retrieve the data from an optional field. Use an `if` statement to check if the value is not empty (`!== ""`).
If the field contains data, push its corresponding page number (e.g., `[3, 3]`) into your `printArray`.
Assign the dynamically built array to the print parameters with `pp.printRange = printArray;`, and then trigger the print dialog using `this.print(pp);`.

Manage and Print Specific PDF Pages with WPS Office
If scripting is too complex, WPS Office provides intuitive visual tools to extract pages with data and print exactly what you need without writing a single line of code.
- 1. Open Your PDF Form: Launch WPS Office and open your multi-page PDF form.
- 2. Fill the Required Fields: Complete the form fields as needed using the interactive PDF tools provided in the software.
- 3. Extract Filled Pages Visually: Navigate to the 'Page' tab and use the 'Extract' tool. Hold the Ctrl key and select only the required pages and the optional pages you just filled out.
- 4. Print the Customized Range: Once the filled pages are extracted into a new document, press Ctrl+P to open the Print dialog and print your customized document.

Frequently Asked Questions
Can I print only filled form pages without using JavaScript?
Without JavaScript, you cannot perform this automatically. You will need to manually determine which pages contain data and specify those page numbers (e.g., 1-3, 5, 8) in the 'Pages to Print' section of your standard Print dialog.
Why isn't my JavaScript print button working in my web browser?
Most built-in PDF viewers in web browsers disable or do not fully support the Acrobat JavaScript API for security reasons. Users must open the PDF form in a dedicated desktop application to utilize dynamic printing scripts.
How do I find the specific names of my form fields to use in the script?
Open your PDF in form editing mode. Right-click the specific form field and select 'Properties'. The exact field name will be displayed in the General tab, which you can copy into your script.




