Skip to content

Instantly share code, notes, and snippets.

@altmind
Last active December 14, 2015 12:28

Revisions

  1. altmind revised this gist Mar 4, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions SplitPages.js
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,6 @@ ProcessDocument = app.trustedFunction(function () {
    newDoc.deletePages(0);
    }


    for (var i = 0; i < newDoc.numPages; i++) {
    if (i < startFrom) continue;

    @@ -63,7 +62,6 @@ ProcessDocument = app.trustedFunction(function () {
    app.endPriv();
    });

    // add the menu item
    app.addMenuItem({
    cName: "splitPagesJS",
    cUser: "Split Pages",
  2. altmind created this gist Mar 4, 2013.
    82 changes: 82 additions & 0 deletions SplitPages.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    ProcessDocument = app.trustedFunction(function () {
    app.beginPriv();
    var newDoc = app.newDoc();

    var p = app.response("Start with page(default 0 - process all pages)?", "Query", "0");
    var startFrom = parseInt(p) || 0;
    var i = 0;
    while (i < this.numPages) {
    newDoc.insertPages({
    nPage: newDoc.numPages - 1,
    cPath: this.path,
    nStart: i
    });
    if (i >= startFrom) {
    newDoc.insertPages({
    nPage: newDoc.numPages - 1,
    cPath: this.path,
    nStart: i
    });
    }

    i++;
    }

    if (newDoc.numPages > 1) {
    newDoc.deletePages(0);
    }


    for (var i = 0; i < newDoc.numPages; i++) {
    if (i < startFrom) continue;

    var cropRect = newDoc.getPageBox("Crop", i);
    var halfWidth = (cropRect[2] - cropRect[0]) / 2;

    var cropLeft = new Array();
    cropLeft[0] = cropRect[0];
    cropLeft[1] = cropRect[1];
    cropLeft[2] = cropRect[0] + halfWidth;
    cropLeft[3] = cropRect[3];

    var cropRight = new Array();
    cropRight[0] = cropRect[2] - halfWidth;
    cropRight[1] = cropRect[1];
    cropRight[2] = cropRect[2];
    cropRight[3] = cropRect[3];

    if (i % 2 == 0) {
    newDoc.setPageBoxes({
    cBox: "Crop",
    nStart: i,
    rBox: cropLeft
    });
    } else {
    newDoc.setPageBoxes({
    cBox: "Crop",
    nStart: i,
    rBox: cropRight
    });
    }

    }
    app.endPriv();
    });

    // add the menu item
    app.addMenuItem({
    cName: "splitPagesJS",
    cUser: "Split Pages",
    cParent: "Document",
    cExec: "ProcessDocument()",
    cEnable: "event.rc = (event.target != null);",
    nPos: 0
    });
    app.addToolButton({
    cName: "splitPagesJSTB",
    cExec: "ProcessDocument()",
    cTooltext: "Split Pages",
    cLabel: "Split Pages",
    cEnable: true,
    nPos: 0
    });