PDF In-Depth

JavaScript - Instant Printing From a PopUpMenu

April 15, 2000


The following JavaScript code can be added to a button, bookmark or even link. When the user activates the button / bookmark / link a popup menu will be displayed on screen listing the page numbers (in page blocks of 20). If the user selects a page number that page will be silently printed to the default printer, no dialog boxes will be displayed.


Acrobat 4.00 contains a return value bug, after running script three times popUp.Menu returns 'null' - restarting application solves the problem. (Bug has been fixed in 4.05)

//  Create an Array to store the Popup menu items
var popupArray = new Array();

// How many pages are in the PDF file.
var numPDFPages = this.numPages;

// ArrayIndex is used to count the number of items in the array
var arrayIndex = 0;
var pageLoop;
var pageLoop2;

//  Fill the array with Menu Headers:
//	(["Page 1- 20","Page 1","Page 2...."],["Page 
21 - 40","Page 21","Page 22..."],)
for (pageLoop = 1; pageLoop < numPDFPages; pageLoop += 20) 

          popupArray[arrayIndex] = "['Page " + 
pageLoop + " - " + (pageLoop + 19);

          for (j = pageLoop; j < pageLoop + 20; j++) 
                   popupArray[arrayIndex] += "','" + j;
          popupArray[arrayIndex] += "'],";
          arrayIndex = arrayIndex + 1;

var completeString = "";
//  Create one long string with all of the array elements
for (pageLoop = 0; pageLoop < arrayIndex; pageLoop++) 
          completeString += popupArray[pageLoop];

// Capture the selected item
var returnValue = eval("app.popUpMenu(" + completeString + 
"'Print Window')"); 

// Process the return value
if (returnValue == 'Print Window')
	     // Show Print Dialog Only
else if (returnValue == null)
	     //You either selected nothing, or your using 
Acrobat 4.0
	     //  Print Document using page range - Silently

	     //  Output complete message
	     app.alert("Page " + returnValue + " printed.");

Copyright Dave Wraight & Planet PDF. No unauthorised reproduction, distribution or publication permitted.

PDF In-Depth Free Product Trials Ubiquitous PDF

Debenu Quick PDF Library

Get products to market faster with this amazing PDF developer SDK. Over 900 functions and an equally...

Download free demo

Five visions of a PDF Day

In the world of PDFs or as we like to say Planet (of) PDF, a year isn't a real PDF year without an intense few days of industry knowledge sharing.

May 15, 2018
Platinum Sponsor

Search Planet PDF
more searching options...
Planet PDF Newsletter
Most Popular Articles
Featured Product

Debenu PDF Aerialist

The ultimate plug-in for Adobe Acrobat. Advanced splitting, merging, stamping, bookmarking, and link control. Take Acrobat to the next level.


Adding a PDF Stamp Comment

OK, so you want to stamp your document. Maybe you need to give reviewers some advice about the document's status or sensitivity. This tip from author Ted Padova demonstrates how to add stamps with the Stamp Tool along with related comments.