-
-
Save novidev/7148247 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
}); | |
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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment