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();
})
@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