Skip to content

Instantly share code, notes, and snippets.

@amoshydra
Created November 23, 2018 02:48
Show Gist options
  • Save amoshydra/ff9ea90487d008cc99ad21e637023c3b to your computer and use it in GitHub Desktop.
Save amoshydra/ff9ea90487d008cc99ad21e637023c3b to your computer and use it in GitHub Desktop.
A script to consolidate pdf consisting of a set of even and a set of odd pages into a single correct paginated PDF file
// Complements: Planet PDF (http://www.planetpdf.com/)
// Source: https://forums.adobe.com/thread/286654?start=40&tstart=0
// Modified by
// - Christian Sass for Acrobat XI compatibility
// - Bernd Alheit for newer Acrobat compatibility
// - amoshydra for comsolidating solution
// Add a menu item to reverse all pages in the active document
app.addToolButton({ cName: "Reverse", cLabel: "Reverse", cExec: "PPReversePages();", cEnable: "event.rc = (event.target != null);"});
app.addToolButton({ cName: "Collate", cLabel: "Collate", cExec: "trustedCollatePages();", cEnable: "event.rc = (event.target != null);"});
function PPReversePages()
{
var t = app.thermometer;
t.duration = this.numPages;
t.begin();
for (i = this.numPages - 1; i >= 0; i--)
{
t.value = (i-this.numPages)*-1;
this.movePage(i);
t.text = 'Moving page ' + (i + 1);
}
t.end();
}
// Collating pages
/*
Title: Collate Document
Purpose: User is prompted to select document to insert/collate.
Author: Sean Stewart, ARTS PDF, www.artspdf.com
*/
trustedCollatePages = app.trustedFunction(function()
{
app.beginPriv(); // Explicitly raise privileges
// create an array to use as the rect parameter in the browse for field
var arRect = new Array();
arRect[0] = 0;
arRect[1] = 0;
arRect[2] = 0;
arRect[3] = 0;
// create a non-visible form field to use as a browse for field
var f = this.addField("txtFilename", "text", this.numPages - 1, arRect);
f.delay = true;
f.fileSelect = true;
f.delay = false;
// user prompted to select file to collate the open document with
app.alert("Select the PDF file to merge with")
// open the browse for dialog
f.browseForFileToSubmit();
var evenDocPath = f.value;
var q = this.numPages;
// insert pages from selected document into open document
for (var i = 0;i < q; i++) {
var j = i*2;
this.insertPages(j, evenDocPath, i);
}
// remove unused field
this.removeField("txtFilename");
app.endPriv();
})
@amoshydra
Copy link
Author

amoshydra commented Nov 23, 2018

Caution:

  1. Be sure to save the combined pdf as a new file if you wish to keep the original odd / even pdfs

Instruction:

  1. Press Download Zip on the top right corner

  2. Extract CollatePages.js into the Javascripts folder of Adobe Reader
    Windows: C:\Program Files (x86)\Adobe\Acrobat DC\Acrobat\Javascripts
    Mac: /iMac/Applications/Adobe Acrobat DC/Adobe Acrobat.app/Contents/Resources/JavaScripts/

  3. Restart Adobe Reader if it was opened

  4. Open the even pages of your pdf

  5. Open the odd pages of your pdf (both files need to stay open during this process, otherwise it may not work for large file)

  6. Click Tools


  7. Click Add-on Tools


  8. Click Collate


  9. Select the odd set of pdf file


  10. Save and done!

@mjasithrive
Copy link

Hello @aamoshydra. It seems something is broken with the script now. I'm using Mac Adobe Acrobat PRO DC 19.012.20040 (19.012.20040) continuous release. Whenever I try to use the script (from the edit menu - it doesn't show up in add-on tools or javascript) it instantly crashes when I press select on the second PDF. Please advise. Here's a link to the crash report ( https://www.dropbox.com/s/0qsncqv72unj1ct/adobeacrobat_2019-08-30-165922_mac-pro.txt?dl=0 ) . I use this script quite a bit, and still wonder why it's not a included in the tools. Thanks in advance for any help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment