Last active
February 3, 2025 08:28
-
-
Save jo-lang/350678c007d2692a95d1fcdacd0d65b0 to your computer and use it in GitHub Desktop.
Script to place all pages of the current InDesign Document as links in a new document for saddle stitch binding
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
// For Adobe InDesign! | |
// this script will make a new file | |
// with the same dimensions as the currently active document | |
// and place the pages as linked files. | |
// The active source document needs a number of pages that is a multiple of 4 (4, 8, 12, 16, ...) | |
// Depending on the submitted pageamount per section | |
// the pages will be placed for saddle stitch binding. | |
// johannes lang january 2025 | |
// not heavily tested, use at own risk! | |
var source_pages_num; | |
var source_doc; | |
if (app.documents.length > 0) { | |
source_doc = app.activeDocument; | |
source_pages_num = source_doc.pages.length; | |
if (source_pages_num%4 != 0) { | |
alert('The number of pages must be a multiple of four (4, 8, 12 ...)!') | |
} | |
else { ask_for_input(); } | |
} | |
else { alert("I need an open document!")} | |
function placeForSaddleStitch(sig_pages_num) { | |
var source_doc = app.activeDocument; | |
var w = source_doc.documentPreferences.pageWidth; | |
var h = source_doc.documentPreferences.pageHeight; | |
var source_pages_num = source_doc.pages.length; | |
var bleed_b = source_doc.documentPreferences.documentBleedBottomOffset; | |
var bleed_l = source_doc.documentPreferences.documentBleedInsideOrLeftOffset; | |
var bleed_r = source_doc.documentPreferences.documentBleedOutsideOrRightOffset; | |
var bleed_t = source_doc.documentPreferences.documentBleedTopOffset; | |
var target_doc = app.documents.add(true); | |
target_doc.documentPreferences.pageWidth = w*2; | |
target_doc.documentPreferences.pageHeight = h; | |
target_doc.documentPreferences.facingPages = false; | |
target_doc.documentPreferences.pagesPerDocument = source_pages_num/2; | |
var source_file = new File(source_doc.filePath + '/' + source_doc.name); | |
for (var i = 0; i < source_pages_num; i++) { | |
var sig_i = Math.floor(i / sig_pages_num) | |
var sig_p_i = i % sig_pages_num | |
if (sig_p_i < sig_pages_num/2) { | |
var target_p_i = sig_p_i; | |
} | |
else { | |
var target_p_i = sig_pages_num - sig_p_i - 1; | |
} | |
target_p_i += sig_i * Math.floor(sig_pages_num/2); | |
app.importedPageAttributes.properties = { | |
importedPageCrop : ImportedPageCropOptions.CROP_BLEED, | |
pageNumber : (i+1) | |
}; | |
var x_pos = i%2 == 0 ? w - bleed_l : -bleed_r; | |
target_doc.pages[target_p_i].place(File(source_file), [x_pos, -bleed_t])[0]; | |
} | |
for (var i = 0; i < target_doc.rectangles.length; i++) { | |
if (Math.floor(target_doc.rectangles[i].geometricBounds[1]) == Math.floor((-1*bleed_r))) { | |
target_doc.rectangles[i].geometricBounds = [-bleed_t, -bleed_r, h+bleed_b, w ]; | |
} | |
else { | |
target_doc.rectangles[i].geometricBounds = [-bleed_t, w, h+bleed_b, 2*w+bleed_r ]; | |
} | |
} | |
} | |
function ask_for_input(){ | |
var theDialog = app.dialogs.add({name:"Place current doc as saddle stich", canCancel:true}); | |
with(theDialog){ | |
with(dialogColumns.add()){ | |
with(borderPanels.add()){ | |
with(dialogColumns.add()) { staticTexts.add({staticLabel:"Pages per signature:"}); } | |
with(dialogColumns.add()) { var intEdit = integerEditboxes.add({editValue: 16, maximumValue: 1024, minimumValue: 4, smallNudge: 4, largeNudge: 16, minWidth: 50});} | |
} | |
} | |
} | |
var feedback = theDialog.show(); | |
if (feedback == true) { | |
var sig_pages_num = intEdit.editValue; | |
if (sig_pages_num %4 != 0) { | |
alert('The pages per signature must be a multiple of four (4, 8, 12 ...)!') | |
} | |
else if (sig_pages_num > source_pages_num) { | |
alert('The pages per signature must be smaller or equal to the the number of pages ('+source_pages_num+')!') | |
} | |
else { | |
placeForSaddleStitch(sig_pages_num); | |
} | |
} | |
else { theDialog.destroy(); } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment