Select page range
Hi,
How to select page range and run our functions with the particular pages?
Selva
Hi,
How to select page range and run our functions with the particular pages?
Selva
Hi All,
Kindly help on this topic.
Selva
The sample script below places emphasis on the dialog used to get the page range from the user. Run the script and then analyze the code. You should be able to apply much of this to your needs. Hope this helps.
try {
//assumes document is open
var docRef = app.documents.item(0);
var maxPages = docRef.pages.count();
//provide variable to hold user's response
var userResponse = dialogWChoices ("Dialog Name", true, "Label here", maxPages);
//enter call to function that processes all pages
if (userResponse[0] == 0) {
myProcess (docRef, 0, maxPages);
} else {
var minPageRef = userResponse[1] - 1;
var maxPageRef = userResponse[2] - 1;
myProcess (docRef, minPageRef, maxPageRef);
}
} catch (e) {
alert (e);
}
alert ("User entered " + userResponse[0] + " " + userResponse[1] + " " + userResponse[2]);
//function to process range of pages
function myProcess (docRef, minPageRef, maxPageRef) {
var thisPage, thisFrame, docOffset;
for (var i = minPageRef; i <= maxPageRef; i++) {
thisPage = docRef.pages.item(i);
docOffset = (thisPage.documentOffset) + 1;
thisFrame = thisPage.textFrames.add({geometricBounds:[36, 72, 100, 300]});
thisFrame.contents = "Hello page " + docOffset
}
}
//function gets page range or "all" from user
function dialogWChoices (dlgName, cancelIt, dLabel, maxPages) {
var userCancelled = false;
var origValue = app.scriptPreferences.userInteractionLevel;
//make sure that user interaction levels will allow a dialog
app.scriptPreferences.userInteractionLevel = UserInteractionLevels.INTERACT_WITH_ALL;
//create the dialog
var dlgRef = app.dialogs.add({name:dlgName, canCel:cancelIt, label:dLabel});
//add a column
var dlgColumn1 = dlgRef.dialogColumns.add();
var dlgColumn2 = dlgRef.dialogColumns.add();
var dlgColumn3 = dlgRef.dialogColumns.add();
//add widgets for first column
dlgColumn1.staticTexts.add({staticLabel: "PageRange:"});
//add widgets to second column
var radioGroup = dlgColumn2.radiobuttonGroups.add();
radioGroup.radiobuttonControls.add({staticLabel:"All", checkedState:true});
radioGroup.radiobuttonControls.add({staticLabel:"Range", checkedState:true});
//add widgets to third column; put reference into a variable
var emptyRow = dlgColumn3.dialogRows.add();
emptyRow.staticTexts.add ({staticLabel: ""});
var inputRow = dlgColumn3.dialogRows.add();
var firstField = inputRow.integerEditboxes.add({minWidth:36, minimumValue:1,maximumValue:maxPages});
inputRow.staticTexts.add ({staticLabel: " thru "});
var secondField = inputRow.integerEditboxes.add({minWidth:36, minimumValue:1, maximumValue:maxPages});
//show the dialog and capture the result
if (dlgRef.show() == true) {
var firstVal = 0;
var secondVal = 0;
var selButton = radioGroup.selectedButton;
if (selButton == 1) {
var firstVal = firstField.editValue;
var secondVal = secondField.editValue;
}
} else {
userCancelled = true;
}
dlgRef.destroy();
app.scriptPreferences.userInteractionLevel = origValue;
if (userCancelled) {
throw ("User Cancelled");
}
//destroy the dialog; script doesn't get here if user cancels
return [selButton, firstVal, secondVal];
}
Already have an account? Login
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.