-
Notifications
You must be signed in to change notification settings - Fork 0
/
Multi-File-Export.jsx
299 lines (256 loc) · 9.66 KB
/
Multi-File-Export.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
/* --------------------------------------
Multi-file Export v1.3
by Aaron Troia (@atroia)
Modified Date: 2/13/22
Description:
Multi-file Export allows you to export multiple PDFs (plus IDML & JPG ) at the same time.
v1.1 - added sig check function, added script name & version to palette
v1.2 - removed redudnant code in sigCheck function
v1.3 - asyncronusExport + cover image export
-------------------------------------- */
#targetengine "session"
var scriptName = "Multi-File Export";
var version = "v1.3"
var g = {};
var d = app.activeDocument;
createDialog();
g.win.show();
/* ========================= */
/* ==== PALLETTE WINDOW ==== */
/* ========================= */
function createDialog() {
// create panel
g.win = new Window("palette", scriptName + " " + version);
g.win.pnlScope = g.win.add("panel");
// CHECKBOXES
// PDF Export checkboxes
g.win.pnlOps = g.win.add("panel", undefined, "PDF Export");
g.win.pnlOps.alignChildren = "left";
g.win.pnlOps.minimumSize = [235,20];
g.win.pnlOps.chkLow = g.win.pnlOps.add(
"checkbox",
undefined,
"Low Resolution"
);
g.win.pnlOps.chkPagesBld = g.win.pnlOps.add(
"checkbox",
undefined,
"PrePress (bleed)"
);
g.win.pnlOps.chkSpreads = g.win.pnlOps.add(
"checkbox",
undefined,
"Prepress (spreads)"
);
// Extra PDF Export checkbox
g.win.pnlOps2 = g.win.add("panel", undefined, "PDF Export (Extra)");
g.win.pnlOps2.alignChildren = "left";
g.win.pnlOps2.minimumSize = [235,20];
g.win.pnlOps2.chkPages = g.win.pnlOps2.add(
"checkbox",
undefined,
"PrePress"
);
g.win.pnlOps2.chkSpreadsBld = g.win.pnlOps2.add(
"checkbox",
undefined,
"Prepress (spreads + bleed)"
);
g.win.pnlOps2.chkHigh = g.win.pnlOps2.add(
"checkbox",
undefined,
"High Quality - No Compression"
);
// IDML checkbox
g.win.pnlIDML = g.win.add("panel", undefined, "IDML Export");
g.win.pnlIDML.alignChildren = "left";
g.win.pnlIDML.minimumSize = [235,20];
g.win.pnlIDML.chkIDML = g.win.pnlIDML.add(
"checkbox",
undefined,
"IDML"
);
// Cover Image checkbox
g.win.coverIMG = g.win.add("panel", undefined, "JPG Export");
g.win.coverIMG.alignChildren = "left";
g.win.coverIMG.minimumSize = [235,20];
g.win.coverIMG.chkIDML = g.win.coverIMG.add(
"checkbox",
undefined,
"Cover JPG"
);
for (var i = 0; i < g.win.pnlOps.length; i++) {
g.win.pnlOps.children[i].value = true;
}
// BUTTONS
g.win.grButs = g.win.add("group");
g.win.grButs.cancel = g.win.grButs.add("button", undefined, "Cancel");
g.win.grButs.check = g.win.grButs.add("button", undefined, "Check");
g.win.grButs.export = g.win.grButs.add("button", undefined, "Export");
// export button
g.win.grButs.export.onClick = function(){
exportPDF();
g.win.close();
}
// check button
g.win.grButs.check.onClick = function() {
SigCheck();
};
// cancel button
g.win.grButs.cancel.onClick = function() {
g.win.close();
};
}
/* ======================== */
/* ==== PDF(s) Export ==== */
/* ======================== */
function exportPDF() {
// These are the PDF Export settings names from InDesign
var preset1 = app.pdfExportPresets.itemByName("PrePress (bleed)");
var preset2 = app.pdfExportPresets.itemByName("Prepress (spreads)");
var preset3 = app.pdfExportPresets.itemByName("Prepress (bleed + spreads)");
var preset4 = app.pdfExportPresets.itemByName("First Chapter");
var preset5 = app.pdfExportPresets.itemByName("PrePress");
var preset6 = app.pdfExportPresets.itemByName("Highest Quality - No Compression");
if (!(preset1.isValid && preset2.isValid && preset3.isValid && preset4.isValid && preset5.isValid && preset6.isValid)) {
alert(
"One of the presets does not exist. Please check spelling carefully."
);
exit();
}
if (d.saved){
thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf";
thePath = String(new File(thePath));
} else {
thePath = String((new File));
}
thePath = thePath.replace(/\.pdf$/, "");
thePath2 = thePath.replace(/(\d+b|\.pdf$)/, "");
// Here you can set the suffix at the end of the file name
name1 = thePath + ".pdf"; // Print PDF
name2 = thePath2 + "_spreads.pdf"; // Spreads PDF
name3 = thePath + ".idml"; // IDML file
name4 = thePath +"_low.pdf"; // Low Resolution file
name5 = thePath +"_high.pdf"; // High Resolutino file
// Prepress (Bleed)
if(g.win.pnlOps.chkPagesBld.value == true){
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
// books
// app.activeDocument.layers.item("Bookline").visible = false; // turn off Bookine layer (if it is visible) for single page export
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1);
};
// Prepress (bleed + spreads)
if(g.win.pnlOps2.chkSpreadsBld.value == true){
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
// app.activeDocument.layers.item("Bookline").visible = false; // turn on Bookline for spreads export
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset3);
};
// Prepress (spreads)
if(g.win.pnlOps.chkSpreads.value == true){
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
// app.activeDocument.layers.item("Bookline").visible = true; // turn on Bookline for spreads export
d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
};
// First Chapter / Low Resolution
if(g.win.pnlOps.chkLow.value == true){
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
// app.activeDocument.layers.item("Bookline").visible = true; // turn on Bookline for spreads export
d.exportFile(ExportFormat.PDF_TYPE, new File(name4), false, preset4);
};
// High Resolution - No Compression
if(g.win.pnlOps2.chkHigh.value == true){
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
// app.activeDocument.layers.item("Bookline").visible = false; // turn on Bookline for spreads export
d.exportFile(ExportFormat.PDF_TYPE, new File(name5), false, preset6);
};
// Prepress
if(g.win.pnlOps2.chkPages.value == true){
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
// books
// app.activeDocument.layers.item("Bookline").visible = false; // turn off Bookine layer (if it is visible) for single page export
d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset5);
};
// IDML
if(g.win.pnlIDML.chkIDML.value == true){
// 1 page cover
app.pdfExportPreferences.pageRange = PageRange.ALL_PAGES;
d.exportFile(ExportFormat.INDESIGN_MARKUP, new File(name3)); // IDML EXPORT
}
// Cover Image
if(g.win.coverIMG.chkIDML.value == true){
exportCover();
}
}
/* =========================== */
/* ==== Signature Check ==== */
/* =========================== */
function sigCheck(){
var pageCount = d.pages.length;
if (pageCount >= 32) {
var sigMod = 16;
} else if (pageCount < 32 && pageCount > 8){
var sigMod = 8;
} else {
alert("There are no sigs, your document is only " + pageCount + " page(s).");
exit();
}
var addPages = ((Math.ceil(pageCount/sigMod)) * sigMod) - pageCount;
var removePages = pageCount - (Math.floor(pageCount/sigMod) * sigMod);
// var perfectBreak = "This document is " + pageCount + " pages. You're good.";
var unperfectBreak = "Your page count " + pageCount + " is not an even signature break. Try adding " + addPages + " pages, or removing " + removePages + " pages.";
if (pageCount % sigMod !== 0){
alert(unperfectBreak);
}
}
/* =============================*/
/* ==== Cover JPG Export ==== */
/* =============================*/
function exportCover() {
app.jpegExportPreferences.properties = {
jpegRenderingStyle: JPEGOptionsFormat.BASELINE_ENCODING,
jpegExportRange: ExportRangeOrAllPages.EXPORT_RANGE,
jpegQuality: JPEGOptionsQuality.MAXIMUM,
jpegColorSpace: JpegColorSpaceEnum.RGB,
// exportingSpread: true, // Uncomment if spreads
simulateOverprint: false,
useDocumentBleeds: false,
embedColorProfile: true,
exportResolution: 300,
antiAlias: true,
}
if (d.pages.length > 6 && d.pages.length <= 64 ) {
// for Signs
app.jpegExportPreferences.pageString = "1"; // Page range, only VALID if EXPORT_RANGE used
} else if (d.pages.length == 3 || d.pages.length == 5) {
// for book covers laid out as separate pages
app.jpegExportPreferences.pageString = "3"; // Page range, only VALID if EXPORT_RANGE used
} else if (d.pages.length == 1){
// for book covers laid out as one page
app.jpegExportPreferences.pageString = "1";
}
if (d.saved) {
thePath = String(d.fullName).replace(/\..+$/, "") + ".jpg";
// thePath = String(d.fullName).replace(/\..+$/, "") + ".jpg";
// thePath = String(new File(thePath).saveDlg()); // use this line if you want the save dialog to show
thePath = String(new File(thePath));
} else {
// thePath = String((new File).saveDlg()); // use this line if you want the save dialog to show
thePath = String(new File());
}
thePath = thePath.replace(/\.jpg$/, "");
// thePath2 = thePath.replace(/(\d+b|\.pdf$)/, "");
name1 = thePath+".jpg";
try {
if (app.activeDocument.layers.item("Bookline").isValid == true){
app.activeDocument.layers.item("Bookline").visible = false; // turn off Bookine layer (if it is visible) for single page export
d.exportFile(ExportFormat.JPG, new File(name1), false);
// alert("Your Cover Image has exported.");
} else { // if no layer named "Bookline" exisits
d.exportFile(ExportFormat.JPG, new File(name1), false);
// alert("Your Cover Image has exported.");
}
} catch (errExport) {
// alert('ERROR: The PDF file is either selected or open.');
alert(errExport.line);
}
}