These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Help on extracting pages

fushyuma
Registered: Jul 27 2011
Posts: 5
Answered

This code extracts a single random page. I'm stuck and don't know what to do to make it extract 3 random pages in a file.
 
var NOP = this.numPages;
this.extractPages (Math.floor(Math.random()*NOP));

My Product Information:
Acrobat Pro 9.0, Windows
gkaiseril
Online
Expert
Registered: Feb 23 2006
Posts: 4307
Accepted Answer
I would assume you want the selection without replacement of selected items, and the pages would be extracted in page number order.

function compareNumbers(a, b) {
// control for numeric sort
return a - b
}

// define array of pages to extract
var aPages = new Array(3);
// possible page to extract
var nPage;
// duplicated page
var bNonDup

// fill array of pages to extract
for(i = 0; i < aPages.length; i++) {
bNonDup = true;
// select a random page number
nPage = Math.floor(Math.random() * this.numPages);
// check for duplicate page in array of selected pages
for(j = 0; j < i; j++) {
if(nPage == aPages[j]) {
bNonDup = false;
}
}
// process page based on being non-duplicate page or duplicate page
if(bNonDup) {
aPages[i] = nPage; // non-duplicate page found - add page
} else {
i--; // duplicate page number - pick a different page
}
}

// sort page array into page number order
aPages.sort(compareNumbers);

// extract selected pages
for(i = 0; i < aPages.length; i++)
this.extractPages(aPages[i]);




George Kaiser

fushyuma
Registered: Jul 27 2011
Posts: 5
This works perfectly. Thanks!!!