Hi, I am currently trying to redorder pages based on names found within each page so I can alphabetize my document. I wrote a script that can find the name I am looking for and successfully store the name and that page number in an array of objects. I can see my search and sort function has been successful when I console.println my sorted array. however, using the this.movePage function to move the actual pages based off of my sorted (alphabetized) array has proven tricky since the page numbers are dynamic and moving one reorders the current document. Do you have a better suggestion on how to move the pages successfully?
TLDR: I have pages sorted in an array that I want the document order to resemble. How do I successfully use this.movePage to accomplish this? (Or is there another way?) Thanks in advance.
Rearranging any list suffers from this problem. Sometimes working backwards in the list solves it, but not here. The simplest solution, but probably not the most efficient, is to renumber your sort list after each move, to reflect the move you just did.
I recommend creating a new file and then adding the pages to it in the correct order.
Logically, that is a simpler solution to code, but my experience of moving pages singly between documents has been that it is very inefficient. May be ok for 20 pages, probably unacceptable for 2000. Result files are also sometimes much, much larger.