Skip to main content
Known Participant
February 5, 2021
Question

Script to reorder pages in alphabetical order

  • February 5, 2021
  • 3 replies
  • 422 views

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 has been closed for replies.

3 replies

Legend
February 5, 2021

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.

try67
Community Expert
Community Expert
February 5, 2021

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

Legend
February 5, 2021

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.