Tips & Tricks

Instant Printing From a JavaScript PopUpMenu

April 14, 2004

Advertisement
Advertisement
 

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.

  • Download JavaScript (1.9 K)

//  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
	     this.print(true,1,1,false);
}
else if (returnValue == null)
{
	     //You either selected nothing, or your using Acrobat 4.0
}
else
{

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

Related Products at PDF Store

Nitro PDF Professional

Nitro PDF Professional, your PDF creation and editing product. Priced at $99, Nitro PDF Pro is the m... View full product details
Download free demo

ARTS PDF Aerialist

Take Acrobat to the next level with advanced splitting and merging; flexible bookmark creation and m... View full product details
Download free demo

ARTS PDF Crackerjack

Impose pages, automate your workflow, verify certified PDFs, print accurate colour separations, conv... View full product details
Download free demo

PDF In-Depth Free Product Trials Ubiquitous PDF

Nitro PDF Professional

the perfect PDF product for business and enterprise, combining an extremely competitive price with a...

Download free demo

XpdfViewer

This ActiveX control (OCX) provides a PDF file viewer component, enabling developers to add PDF viewing...

Download free demo

Ubiquitous PDF: PDF eBooks-Library

If you are looking for a good store of PDF content, you could do a lot worse than visiting eBooks-Library.com...

September 03, 2009
Search Planet PDF
more searching options...







Download PDF Creator

Download The Best of Planet PDF volume 2
Planet PDF Newsletter
Most Popluar Articles
Features

Collating PDFs using JavaScript

Despite the numerous benefits, there can be potential issues with the conversion of paper documents into electronic archives. When scanning paper pages into PDF, it's possible to end up with the odd- and even-numbered pages in separate PDF files. It can be very time-consuming to collate them manually, but there is an easier way. Sean Stewart explains.

Featured Product

BCL easyPDF SDK

BCL easyPDF SDK is a set of PDF Programming Libraries designed specifically to help Software Developers / Programmers build and deploy enterprise class PDF applications for corporate wide PDF...

Platinum Sponsor
Create & Edit PDF - Nitro PDF Software

ARTS PDF

Silver Sponsors

PDF-Tools enfocus

QuickPDF: The Unrivaled PDF Developer Toolkit