Skip to main content
Participant
August 7, 2025
Answered

How to shuffle PDF pages randomly

  • August 7, 2025
  • 1 reply
  • 708 views

Hello,

I have a multipage PDF with about 500 pages. The pages contain variable content, so each page looks slight different. I am looking for a way to shuffle the page or in other words to automatically and randomly mix pages in the page position. So that i.e page one becomes page 300 and page 488 becomes page 2 and so forth. I do not want to do a manual page move.

Any idea?

Correct answer try67

You can do it by executing this JavaScript code, for example from a Custom Command. Edit the value in the first line to change the number of "shuffles" that will take place. Even with a low number you will get pretty good results, as both the source page and the target page are random.

 

var numShuffles = 500;
for (var i=0; i<=numShuffles; i++) {
	var sourcePage = Math.floor(Math.random()*this.numPages);
	var targetPage = Math.floor(Math.random()*this.numPages);
	this.movePage(sourcePage, targetPage);
}

 

1 reply

try67
Community Expert
try67Community ExpertCorrect answer
Community Expert
August 7, 2025

You can do it by executing this JavaScript code, for example from a Custom Command. Edit the value in the first line to change the number of "shuffles" that will take place. Even with a low number you will get pretty good results, as both the source page and the target page are random.

 

var numShuffles = 500;
for (var i=0; i<=numShuffles; i++) {
	var sourcePage = Math.floor(Math.random()*this.numPages);
	var targetPage = Math.floor(Math.random()*this.numPages);
	this.movePage(sourcePage, targetPage);
}

 

MikeDomAuthor
Participant
August 7, 2025

That code shows a syntax error when using Javascript in Acrobat Pro on an open multipage PDF. Can you guide me on how to use your code on a PDF. I'm not a programmer unfortunatelly.

 

Thanks

Mike

try67
Community Expert
Community Expert
August 7, 2025

There's no syntax error. Either you edited it incorrectly or you're not running the full code. You don't need to be a programmer. Just run it as-is from a Custom Command or the JS Console. If you're doing the latter make sure to select all of it before executing it.