PDF Printing Issues

How to Print Selected PDF Pages Double-Sided with JavaScript

Maira MehtabMaira Mehtab Oct 28, 2026 870 views

Question details

The user wants to configure a button within a multi-page PDF form to automatically print a specific range of pages in double-sided mode using JavaScript.

How to Print Selected PDF Pages Double-Sided Using JavaScript
Product
PDF/Adobe Acrobat
Device & OS
not provided
Scenario
Developing an interactive PDF form where a custom button acts as a shortcut to print only specific pages duplex, bypassing manual print settings.
Observed behavior
The user needs the correct JavaScript syntax for defining page ranges and duplex modes, and is looking for a way to fully suppress the native print confirmation pop-up.
Before you start

Ensure you have a PDF editor that supports advanced JavaScript execution and verify that your physical printer hardware supports duplex (double-sided) printing.

Solution 1Recommended

Use Print Parameters to Set Duplex Mode and Page Range

Implement JavaScript using the getPrintParams() method to define the duplex type and specific page numbers before triggering the print action.

JavaScript in PDFs allows you to automate repetitive printing tasks. By customizing the print parameters, you can force the printer to flip on the long edge and restrict the print job to a specific page array. Note that JavaScript in PDFs uses 0-based indexing, meaning page 1 is represented as 0.

1
Open JavaScript settings

Access the properties of your print button in your PDF form builder and navigate to the Actions tab to add a new 'Run a JavaScript' action.

2
Initialize print parameters

Start your script by calling the print parameters object: var printParams = this.getPrintParams();

3
Define duplex settings

Set the duplex mode to long-edge binding by adding: printParams.DuplexType = printParams.constants.duplexTypes.DuplexFlipLongEdge;

4
Specify the page range

Define your start and end pages using 0-based indexing. For example, to print pages 10 through 17, type: printParams.firstPage = 9; printParams.lastPage = 16;

5
Execute the print command

Finalize the script by calling the print function with your defined parameters: this.print(printParams);

Use Print Parameters to Set Duplex Mode and Page Range
Security Restrictions on Print Dialogs: For security reasons, modern PDF readers will usually still display a print confirmation dialog to prevent unauthorized silent printing. Fully suppressing this pop-up is restricted by the PDF viewer's core security settings and cannot be bypassed safely via standard JavaScript.
Effortless PDF Printing

Easily Print Specific PDF Pages Double-Sided with WPS Office

If you want to avoid dealing with complex JavaScript codes and security restrictions, WPS Office provides a straightforward, user-friendly interface to quickly print selected PDF pages in duplex mode without any programming.

  1. 1. Open the PDF: Launch WPS Office and open your multi-page PDF document.
  2. 2. Access the Print menu: Click on 'Menu' in the top-left corner and select 'Print', or simply press the Ctrl+P keyboard shortcut.
  3. 3. Select pages to print: In the Print dialog box, locate the 'Pages to Print' section and enter your specific page range (e.g., 10-17).
  4. 4. Enable duplex printing: Check the box for 'Print on both sides of paper' and select 'Flip on long edge' from the dropdown menu.
  5. 5. Confirm and print: Click the 'Print' button at the bottom of the dialog to securely and efficiently print your selected pages.
Intuitive print dialog for quick page range selectionBuilt-in double-sided (duplex) printing supportHighly compatible with Adobe PDF files and interactive formsLightweight application with fast document rendering
microsoft office alternative - wps office

Frequently Asked Questions

Why does the print confirmation dialog still appear when using JavaScript?

Modern PDF readers enforce security policies that prevent 'silent printing' (printing without user consent). This ensures malicious scripts cannot print documents automatically and deplete your paper or ink. Therefore, the confirmation dialog will still appear even if duplex and page parameters are predefined.

Why are my printed page numbers off by one when using the JavaScript code?

Acrobat JavaScript uses zero-based indexing for page numbers. This means the first page of your PDF is recognized as page 0. If you want to print pages 10 through 17, you must set the firstPage property to 9 and the lastPage property to 16.

Can I modify the script to flip on the short edge instead?

Yes. To print double-sided by flipping on the short edge, change the duplex property in your JavaScript code to: printParams.DuplexType = printParams.constants.duplexTypes.DuplexFlipShortEdge;