Print Page | Close Window

Print Page Ranges with Reader

Printed From: Debenu Quick PDF Library - PDF SDK Community Forum
Category: For Users of the Library
Forum Name: Sample Code
Forum Description: Share Debenu Quick PDF Library sample code with other forum members
URL: http://www.quickpdf.org/forum/forum_posts.asp?TID=250
Printed Date: 22 Nov 24 at 7:05PM
Software Version: Web Wiz Forums 11.01 - http://www.webwizforums.com


Topic: Print Page Ranges with Reader
Posted By: chicks
Subject: Print Page Ranges with Reader
Date Posted: 10 Jan 06 at 1:31PM
I've slightly modified a JavaScript example from Sean Stewart of ARTS PDF so that it will add a menu item to Adobe Reader to allow printing page ranges, e.g. "1,5,10-19,25"

Just save the JavaScript as "PrintPageRanges.js" to the JavaScript subfolder in your Adobe Reader directory, and it will add a "Print Page Ranges" item to the "File" directory next time you start Reader.

You can also attach the original code to a button on your PDF using iSEDQuickPDF.

http://www.planetpdf.com/developer/article.asp?ContentID=6873

/*
Title: PRINT USER DEFINED PAGE RANGE
Author: ARTS PDF, Sean Stewart
Purpose: Prompt user to enter required page
        range to print, e.g. 1-5,7,9-20
*/

var PrintPageRanges = app.trustedFunction(function()
{
//Get user response
var cResponse = app.response({
cQuestion: "Enter in the pages you wish to print, e.g. 1,5,10-19,25",
cTitle: "Print",
cDefault: "",
cLabel: "Pages:"
});

if ( cResponse == null) {
    app.alert("No pages entered");
} else {
   var strInput = cResponse;
   var strChar;
   var arPrint = new Array(10);
   var arCount = 0;
   arPrint[arCount] = "";

for (var i = 0; i < strInput.length; i++){

strChar = strInput.substr(i,1);

    //Check character and form page group
    if (IsInteger(strChar) == 0){
        arPrint[arCount] = arPrint[arCount] + strChar;
    }

    if (IsDash(strChar) == 0){
        arPrint[arCount] = arPrint[arCount] + strChar;
    }

    if (IsComma(strChar) == 0){
        arCount++;
        arPrint[arCount] = "";
    }

}

for (i=0;i<(arCount+1);i++){

     if (arPrint[i].indexOf("-") > 0){
            var dashPos;
            dashPos = (arPrint[i].indexOf("-"));

            var pageStart = arPrint[i].substr(0,dashPos);
            var pageEnd = arPrint[i].substr(arPrint[i].indexOf("-")+1,
                          (arPrint[i].length - dashPos+1));

            this.print({
               bUI: false,
               nStart: pageStart - 1,
               nEnd: pageEnd - 1,
               bSilent: true
               });

     } else {
            this.print({
               bUI: false,
               nStart: arPrint[i] - 1,
               nEnd: arPrint[i] - 1,
               bSilent: true
               });
     }
}
}

});


function IsComma(strChar){

    if (strChar == ",") {
        return 0;
    } else {
        return -1;
    }
}

function IsSpace(strChar){
    if (strChar == " ") {
        return 0;
    } else {
        return -1;
    }
}

function IsDash(strChar){
    if (strChar == "-") {
        return 0;
    } else {
        return -1;
    }
}

function IsInteger(strChar){
    if (strChar >=0 || strChar <= 9) {
        return 0;
    } else {
        return -1;
    }
}

app.addMenuItem({cName:"Print Page Ranges",cParent:"File",cExec:"PrintPageRanges();"});



Print Page | Close Window

Forum Software by Web Wiz Forums® version 11.01 - http://www.webwizforums.com
Copyright ©2001-2014 Web Wiz Ltd. - http://www.webwiz.co.uk