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

Moving Pages Problem

JNorris
Registered: Sep 7 2011
Posts: 31
Answered

So the script I've written will move pages if they meet a certain bookmark name to the bottom of the file. I have a problem though, because I want to do it in a certain order. If I repeat the process then the "count" will be off because pages have already been moved. So I'm really stuck. Note: I don't want to cycle through the entire array of names at the same time, so that I can define an order.
  
var number = new Array();
var k=0;
var bknames = new Array ();
 
function DumpBookmark(bkm, nLevel)
{
var s = "";
for (var i = 0; i < nLevel; i++) s += " ";
if (bkm.name != "Root") {
bkm.execute();
number[k] = this.pageNum;
bknames[k] = bkm.name;
k++;
}
if (bkm.children != null)
for (var i = 0; i < bkm.children.length; i++)
DumpBookmark(bkm.children[i], nLevel + 1);
}
DumpBookmark(this.bookmarkRoot, 0);
 
var count=0;
var startpg=0;
var endpg=numPages-1;
var trigger =0;
var ss = new Array ();
ss[0] = "blahblah";
ss[1] = "blahblah";
ss[2] = "blahblah";
 
function test(c, count) {
for (var n = 0; n < numPages; n++){
 
for (i = 0; i<=k; i++) {
if (number[i] == n) {
for ( var r=c; r < c+1; r++) {
if (bknames[i] == ss[r]) {
startpg = number[i];
for (var y = (startpg+1); y < numPages; y++){
for (var x = 0; x<=k; x++){
if (number[x] == y) {endpg=number[x]-1; x=k; y=numPages; trigger=1;}
if (trigger==0) {endpg = numPages-1; }
}
}
endpg= endpg - count;
startpg= startpg - count;
app.alert("Start = " + startpg + " and End = " + endpg, 3);
for (z=0; z < (endpg-startpg)+1; z++) {
this.movePage(startpg,this.numPages - 1);
}
count++;
count = count + endpg - startpg;
trigger=0;}}}}}}
}
 
test(0,0);
test(1,0);
etc...
  
How should the count be modified each cycle?

My Product Information:
Acrobat Pro 10.0, Windows
JNorris
Registered: Sep 7 2011
Posts: 31
Sorry, to clarify. Here's an example.

Bookmark 1 is on pg 1
Bookmark 2 is on pg 5.

The program will drop pages 1-4 to the bottom, assuming "Bookmark 1" is on my list of bookmarks to drop.
try67
Expert
Registered: Oct 30 2008
Posts: 2401
Without going over your entire code I'll give you a general tip to avoid these kind of problems: Iterate from the last element to the first, instead of the other way around. I think that in your case you should do it in the for-loop that actually moves the page(s), but your code is a bit difficult to follow since it's not documented at all so I might be wrong there...

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

JNorris
Registered: Sep 7 2011
Posts: 31
Accepted Answer
What the count was used for was seeing how the pages shifted after each page move. Therefore, all I had to do was reacquire my list of bookmarks and corresponding page numbers. Simply set k=o, and use function DumpBookmarks.