Skip to main content
Known Participant
February 5, 2021
Question

Script to reorder pages alphabetically

  • February 5, 2021
  • 2 replies
  • 1268 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.

2 replies

try67
Community Expert
Community Expert
February 8, 2021

I recommend creating a new file and inserting the pages to it in the correct order. It's much easier (although maybe a bit less efficient) them moving them around in the original file.

Bernd Alheit
Community Expert
Community Expert
February 5, 2021

After the move of a page update the page numbers in the array. 

Known Participant
February 5, 2021

Thank you for your response, but I am not seeing how that would help my problem. (Could be that I'm just missing something) But currently my array in the console looks like this shown below. I am using this.movePage() fn to reorder the pages in my document based off this array. but the parameters for the function are based on what page number to move it after. So if I say this.movePage(5, 1), I would hope that it places it second in order just as it is in my array, but the way adobe dynamically renders the page number order makes it difficult to know what that page will be that I need to place the new page after. Does that make sense? I feel like I might now be explaining it well.

 

var sortedNames = [
  { name: 'BERGERON', page: 3 },
  { name: 'Breaux', page: 5 },
  { name: 'CALDWELL', page: 6 },
  { name: 'Cantu', page: 12 },
  { name: 'Choe', page: 7 },
  { name: 'Curren', page: 8 },
  { name: 'Guevara', page: 9 },
  { name: 'Hearing', page: 4 },
  { name: 'Ross', page: 1 },
  { name: 'SALINAS', page: 2 },
  { name: 'Starks', page: 10 },
  { name: 'Ziegler', page: 11 }
]

 

Known Participant
February 5, 2021

CORRECTION:

this.movePage(5, 0)
should move it to the second position bc it is 0-indexed