• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Randomize pdf pages

New Here ,
Feb 17, 2016 Feb 17, 2016

Copy link to clipboard

Copied

Hello all, thanks for taking the time to read this. Not sure if this is the most appropriate forum. I use notecards to study that I type in word and save as pdfs. They are all laid out the same: the odd numbered pages are the front and the next even page is the back. Is there a way to randomize a pdf document so that I can shuffle the deck, so to speak, such that it is always odd then odd+1?

If you are interested, I can send you a sample pdf of my notecards, I must have close to 10,000 of them from medical school through residency, but the lack of being able to shuffle them really does hinder studying a bit. I would definitely be willing barter for your help. Message me back and we can exchange emails. Thanks,

-jason

TOPICS
Acrobat SDK and JavaScript

Views

7.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 17, 2016 Feb 17, 2016

It's maybe not the best code in the world, but it should get the job done. Run it from the Console window, or attach it to a button to have easy access to it:

for (var p=0; p<this.numPages; p++) {

    this.movePage(p, Math.floor(Math.random()*(this.numPages-1)));

}

Votes

Translate

Translate
Community Expert ,
Feb 17, 2016 Feb 17, 2016

Copy link to clipboard

Copied

It's maybe not the best code in the world, but it should get the job done. Run it from the Console window, or attach it to a button to have easy access to it:

for (var p=0; p<this.numPages; p++) {

    this.movePage(p, Math.floor(Math.random()*(this.numPages-1)));

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 17, 2016 Feb 17, 2016

Copy link to clipboard

Copied

Thanks for the quick reply! I'll let you know how it works.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 03, 2017 Oct 03, 2017

Copy link to clipboard

Copied

Did you get it to work?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2017 Oct 04, 2017

Copy link to clipboard

Copied

Looks good to me. Did you try it benh?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 04, 2017 Oct 04, 2017

Copy link to clipboard

Copied

I didn't end up using this piece of code, no, as I was unfamiliar with the Console.

If you’d like my DIRTY solution, here it is:

I had a 330-page PDF to split and randomize.

In Automator, I used a Finder action. You can build it yourself by searching under “Actions” for “Ask for Finder Items” (drag this into the first position), and “Split PDF” (drag this into the second position).

split-automator.gif

Run this script on the PDF you need to split. It will save as single pages.

Then open Apple Script Editor, paste this into the script editor window:

tell application "Finder"

  repeat with this_item in (get items of window 1)

  set name of this_item to ((random number from 1000 to 5000) & "." & name extension of this_item) as string

  end repeat

end tell

Before you run this script - copy all of your single-page PDFs to a secure location for back up.

Then ensure all Finder windows are closed (the script changes filenames on ANY FILE IN THE TOP FINDER WINDOW! Do not run this script on your Applications folder.

Open the Finder window with the single-page PDFs inside and press the RUN key. The script will change some filenames, then probably crash and say “There is a duplicate filename”. 😕

At this point, scoop all the renamed PDFs into a KEEP folder and press run again, and again, and again, until all the PDFs are renamed. Careful to hit the “Keep Both” button when the Finder asks of you want to replace files as you move them.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2020 Apr 03, 2020

Copy link to clipboard

Copied

Thank you much for this wonderful code.  I have a very similar need and I tried the code and although it did randomize the pages my need is unique because my pages are Trading Cards and the Front and Backs must remain together after the pages are randomized.  Card 1 Front is Page 1, Card 1 Back is Page 2.  Then Card 2 Front is Page 3, Card 2 Back is Page 4.  Then Card 3 Front is Page 5, Card 3 Back is Page 6.  And so on.  The file has 252 pages (126 trading cards).  The goal is to randomize the cards before I print and package them.  Thanks in advance!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

I didn't test it, but try this version:

 

for (var p=0; p<this.numPages-1; p+=2) {
    var newPageNum = Math.floor(Math.random()*(this.numPages-2));
	if (newPageNum%2!=0) newPageNum++;
	this.movePage(p, p+1, newPageNum);
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Thanks for the quick reply!  I tried the new version and it actually just switches the position of the card front and back but keeps all the cards in order.  So now Card 1 Front is Page 2 (was page 1), Card 1 Back is Page 1 (was page 2).  Then Card 2 Front is Page 4 (was page 3), Card 2 Back is Page 3 (was page 4).  Then Card 3 Front is Page 6 (was page 7), Card 3 Back is Page 7 (was page 6).  And so on. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2020 Apr 04, 2020

Copy link to clipboard

Copied

Sorry, my bad. The last line of code is incorrect. This is actually a bit more complicated than I thought because you have to take into account whether the new page to which the pages are moved is before or after them...

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 04, 2017 Oct 04, 2017

Copy link to clipboard

Copied

Thanks for sharing that. Looks like a lot more work though. The console is in Acrobat Pro, search tools in Acrobat Pro DC for JavaScript.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

Is there any reason why this wouldn't work for an 18,000+ page .pdf? It was working for smaller page .pdfs for me, but this big one just spins the beach ball. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 03, 2020 Nov 03, 2020

Copy link to clipboard

Copied

LATEST

I would say it's probably too much for Acrobat to handle, unfortunately, although the Mac version (which I assume you have since you referenced the "beach ball") of Acrobat DC (and maybe 2020?) is 64-bit, so it should work better than the Windows one... But 18K+ pages might be too much, even for that.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines