PDF Printing Issues

How to Print Specific PDF Pages Based on Selected Checkboxes

Ayan MasoodAyan Masood Nov 2, 2026 869 views

Question details

The user needs to create a single print button in a PDF document that prints specific pages or attached documents depending on which checkboxes have been selected.

How to Print PDF Pages Based on Selected Checkboxes
Product
PDF Interactive Forms
Device & OS
not provided
Scenario
A user is designing an interactive PDF form containing multiple optional sections. They want to allow readers to select desired sections via checkboxes and click a unified button to print only the chosen page ranges.
Observed behavior
A JavaScript print-parameter object evaluates the state of each checkbox and executes the print command for the corresponding page ranges without printing the entire document.
Before you start

Verify that your PDF editing software supports JavaScript for interactive forms, and make a note of the exact field names for all checkboxes and the zero-based page index ranges they correspond to.

Solution 1Recommended

Use JavaScript to Trigger Selective Printing

By assigning a custom JavaScript action to a form button, you can evaluate which checkboxes are checked and send specific print parameters to the printer.

PDF JavaScript uses a zero-based index for page numbers (e.g., page 1 is index 0). You must create a print parameter object for each document or section and configure the script to check the value of the corresponding checkbox before executing the print command.

1
Create and name your checkboxes

Open your document in form editing mode. Insert your checkboxes next to the options you want users to select. Assign each checkbox a unique, identifiable name (e.g., 'Check_Doc1', 'Check_Doc2') and set their export values (usually 'Yes' by default).

2
Insert the master print button

Add a standard push button to your form. Label it 'Print Selected Documents' or similar. Right-click the button, access its Properties, and navigate to the Actions tab.

3
Add the JavaScript print parameters

Set the action trigger to 'Mouse Up' and the action type to 'Run a JavaScript'. In the editor, construct your print parameters. Use the 'getPrintParams()' method to define 'firstPage' and 'lastPage' for each section.

4
Set conditional print triggers

For each section, add an 'if' statement that checks the box value. For example: if (this.getField('Check_Doc1').value == 'Yes') { var pp = this.getPrintParams(); pp.firstPage = 2; pp.lastPage = 6; this.print(pp); } Repeat this logic sequentially for all checkboxes so one button click processes all selections.

Use JavaScript to Trigger Selective Printing
Sequential Printing Output: Because the script triggers separate print commands for each checked box, the printer will process them as separate print jobs rather than a single continuous document.

Easily Manage and Print Custom PDF Pages in WPS Office

If you prefer a code-free approach to managing your document output, WPS Office offers a robust PDF editor that makes it incredibly easy to select, extract, and print specific pages or ranges without relying on complex JavaScript.

  1. 1. Open the PDF document: Launch WPS Office and open your multi-section PDF file.
  2. 2. Access the print menu: Click the Print icon on the top toolbar or press Ctrl + P to open the Print dialog box.
  3. 3. Specify page ranges: Under the 'Pages to Print' section, select the 'Pages' option and manually type the specific page numbers or ranges (e.g., 1-5, 8, 11-14) that correspond to the sections you need.
  4. 4. Print your selection: Review your printer settings and click 'Print' to generate the document containing only your selected pages.
Fully compatible with standard PDF forms and documentsIntuitive print interface for custom page range selectionLightweight alternative to resource-heavy PDF editorsComprehensive suite of free PDF editing and conversion tools
microsoft office alternative - wps office

Frequently Asked Questions

Will this JavaScript print button work in free PDF readers?

Yes, standard JavaScript print functions (like this.print) are generally supported in free readers such as Adobe Acrobat Reader and WPS PDF, provided the document does not have severe security restrictions blocking print actions.

Why is my PDF JavaScript printing the wrong pages?

PDF JavaScript uses a zero-based index for page numbering. This means page 1 is represented as 0, page 2 as 1, and so on. If your code targets firstPage = 2, it will actually print starting from the 3rd page of the document.

Can I hide the print button so it doesn't appear on the printed paper?

Yes. In the button's Properties under the General tab, you can set the Form Field property to 'Visible but doesn't print'. This ensures the button remains clickable on the screen but won't ruin your physical output.