Last active
December 14, 2015 12:28
-
-
Save altmind/5086328 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
}); |
An odd problem I found. When I choose an odd-numbered page for the page to start on, the pages go out of order (15, 14, 17, 16, etc). When I choose an even-numbered page for the start page, the pages are in order.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
hi, altmind
your script is a good work, but i have only one problem. it is about right-to-left pdf files, i can split them with no errors except for i get the reverse order of odd and even pages, so i have to extract all pages rename and combine again. i wondered if this can be fixed in the script.
if you have time to fix this I'll be appreciating.
thanks in advance.