// *****************************************************
// ** INFO:
// ** 1.) Open Acrobat>6
// ** 2.) Press Ctrl+j to open JS-Console
// ** 3.) Delete content from console and Paste this Code into console
// ** 4.) Modify parameters myCatChap AND myInitialPageNo to match document-link requirements!
// ** 5.) IMPORTANT: select whole content (Ctrl+a) and then press enter on the number block (!) OR Ctrl+Enter on keyboard
// ** 6.) Code is executed an a weblink is inserted to every page
// ** 7.) Delete the Script from the console again and save your document
// ** 
// ** Keywords: ECMA Script, AcroJS, Acrobat Document Object Model (ADOM)
// ** Links: http://partners.adobe.com/public/developer/pdf/topic_js.html
// **
// ** 08.11.2005 mtidona@businex.de
// **


// *****************************************************
// ** SET INITIAL VALUES FOR EVERY DOCUMENT HERE

var myCatChap 	    = "30A"; //1st digit as cat-no, 2nd and 3rd digits zeroed chapter-no
var myInitialPageNo = 15;


// *****************************************************
// NO CHANGES BELOW THIS LINE
// *****************************************************


// *****************************************************
// ** FUNCTIONS

function PadNumber3(Num) {
  var T = Num + '';
  while (T.length<3) { T = '0' + T; }
  return T;
}

// *****************************************************
// ** APPLY LINK TO EVERY PAGE

for (var i=0; i<this.numPages; i++) {

    // **get coordinates of the page
    var cropBox = this.getPageBox("Crop", i);
    
    // **coordinates for rectangle
    var myRect = [0, cropBox[1], cropBox[2], 0];
	
    // **create link object
    var myLink = this.addLink(i, myRect);
    	
    // **set link value
    var mySingleDigitPageNo = myInitialPageNo + i;
    var myThreeDigitPageNo = PadNumber3(mySingleDigitPageNo);
    var myParam = myCatChap + myThreeDigitPageNo;
    var myWebLink = "http://www.mywebsite.de/display_sth_for_this_page.php?pagestring=" + myParam;
    
    // **set link action
    myLink.setAction("this.getURL('" + myWebLink + "')");
    
    //app.alert("Link " + myWebLink + " in Seite Nr. " + myThreeDigitPageNo + " eingefuegt.");
}

// *****************************************************
