Create an Acrobat Button to Print Page Ranges from Checkboxes
Question details
Create an Acrobat form button that prints PDF page ranges according to selected checkboxes.

- Product
- Adobe Acrobat
- Device & OS
- not provided
- Scenario
- A PDF form contains checkboxes that determine which page ranges should be printed.
- Observed behavior
- The desired result is for only the print commands associated with selected checkboxes to run.
Confirm that the PDF has the required checkbox fields and enough pages for the ranges you plan to print. Note each field name in Acrobat's Prepare a Form tool and test the script in a PDF viewer that supports Acrobat JavaScript.
Add a conditional print script to an Acrobat form button
Use this approach when each selected checkbox should trigger a specific page range.
Put every statement controlled by an if condition inside curly braces. Without braces, only the first following statement is conditional.
The example uses checkboxes named SectionA and SectionB and a PDF with at least four pages. Acrobat JavaScript uses zero-based page indexes, so 0–1 means PDF pages 1–2.
Open the PDF in Acrobat and choose All tools > Prepare a form. Check the checkbox field names in their Properties, or rename them SectionA and SectionB for the example.
In Prepare a form, add or select a button and open its Properties. On the Actions tab, choose Mouse Up as the trigger and Run a JavaScript as the action, then select Add.
In the JavaScript editor, enter the following text, then save the action and button properties: var a = this.getField("SectionA"); var b = this.getField("SectionB"); if (!a || !b) { app.alert("Check the checkbox field names."); } else if (this.numPages < 4) { app.alert("This example requires at least four pages."); } else if (a.value === "Off" && b.value === "Off") { app.alert("Select at least one section."); } else { if (a.value !== "Off") { this.print({bUI: true, nStart: 0, nEnd: 1}); } if (b.value !== "Off") { this.print({bUI: true, nStart: 2, nEnd: 3}); } }
Save the PDF, exit form editing, and click the button with each checkbox selected individually and then with both selected. Check the ranges in the print dialogs before confirming them.

Print selected PDF ranges manually in Acrobat
Use manual printing when you do not need a checkbox-driven button or want to verify the ranges first.
Print PDF Page Ranges Manually with WPS Office
WPS Office is a free, lightweight alternative with a familiar interface for working with PDFs and Office files. It can help you print selected PDF pages manually, but it does not replace the Acrobat JavaScript button described above.

Frequently Asked Questions
Why does a print command run when its checkbox is not selected?
Check the if statement in the button's JavaScript. Without curly braces, only the first statement immediately after the condition is controlled by it; put all related statements between { and }.
How do I find a checkbox's field name?
In Acrobat, open All tools > Prepare a form, select the checkbox, and open its Properties. Use its field name exactly in the script's this.getField call.
Why does the script use 0 for the first page?
Acrobat JavaScript page indexes start at 0. For example, nStart: 0 and nEnd: 1 specify the first and second PDF pages.
Can I print both checkbox ranges in one job?
The example calls this.print once for each selected checkbox, so it can create separate dialogs or jobs. For a manual single job, choose File > Print and enter the desired ranges in the Pages field.




