Skip to main content
Known Participant
Feb 5, 2021 7:35 PM UTC
Question

Script to reorder pages in alphabetical order

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.

This topic is closed to new replies. Start a new post to keep the conversation going.

3 replies

Legend
Feb 5, 2021 10:58 PM UTC

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.

Translate
try67
Community Expert
Community Expert
Feb 5, 2021 10:56 PM UTC

I recommend creating a new file and then adding the pages to it in the correct order.

Translate
Legend
Feb 5, 2021 10:55 PM UTC

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.

Translate