#target indesign
var myPDFFile = File.openDialog("Choose a PDF File", "PDF files:*.PDF");
if(myPDFFile == "" || myPDFFile == null)
exit(0);
var Width = 148;
var Height = 210; /// укажи дообрезной формат блока
var name = "test"; /// укажи номет ТЗ
var pathToFolder = "~/Desktop/1/";// папка для спуска
var bbArray = [24,24,24,24,20,20,20,24]; // укажи объём тетрадей
startBookletPages = 0;
for(var i = 0; i < bbArray.length; i++){
myDocument = app.documents.add();
myDocument.windows[0].minimize();
with (myDocument.viewPreferences){
horizontalMeasurementUnits = MeasurementUnits.millimeters;
verticalMeasurementUnits = MeasurementUnits.millimeters;
}
with(myDocument.documentPreferences){
masterTextFrame = false; // - не создаем. Если masterTextFrame = true, то он будет создаваться
facingPages = false; // при true документ будет создан разворотами, при false - из отдельных страниц
pageHeight = Height +"mm";
pageWidth = Width*2+"mm";
pageOrientation = PageOrientation.landscape; // или pageOrientation = PageOrientation.portrait;
pagesPerDocument = 1;
startPageNumber = 1; // Этот параметр лежит в пределах 1-999999.
intent = DocumentIntentOptions.PRINT_INTENT;
}
myPage = myDocument.pages.item(0);
myPlacePDF(myDocument, myPage, myPDFFile, bbArray[i], startBookletPages);
startBookletPages = +startBookletPages + bbArray[i]; // счётчик первой стр в тетради
var bookletSig = myDocument.pages.item(0).graphicLines.add();
bookletSig.properties={name:"BookSig",strokeColor:[0,0,0,100], geometricBounds:[ (20+i*((Height-35)/30)) +"mm", (Width - 1.5)+ "mm", (20+i*((Height-35)/30)) +"mm", (Width + 1.5) + "mm"], strokeWeight: 4};
var bookletSigNumber = myDocument.pages.item(0).textFrames.add();
bookletSigNumber.properties= {geometricBounds: [(15+i*((Height-35)/30)), (Width - 3), (20+i*((Height-35)/30)),(Width + 3)], contents: (i +1).toString(), verticalJustification : VerticalJustification.TOP_ALIGN};
myDocument.stories[0].justification=Justification.CENTER_ALIGN;
myDocument.stories[0].pointSize = 10;
var bookSig = myDocument.pages.item(0).graphicLines.add();
bookSig.properties={name:"BookSig",strokeColor:[0,0,0,100], geometricBounds:[ (Height -15) +"mm", (Width - 1.5)+ "mm", (Height -15) +"mm", (Width + 1.5) + "mm"], strokeWeight: 4};
// сохранялка
myDocument.documentPreferences.facingPages = false;
var secondName = +1+i ;
myDocument.save(new File(pathToFolder +"/"+name+"_t"+secondName+".indd"));
//myDocument.windows[0].restore();
var myPDFExportPreset = app.pdfExportPresets.item("FieryOptimized (CMYK)");
app.pdfExportPreferences.pageRange='1-40';
saveFile = new File(pathToFolder +"/"+name+"_t"+secondName+".pdf");
myDocument.exportFile(ExportFormat.pdfType, saveFile, false);
myDocument.close(SaveOptions.NO);
}
function myPlacePDF(myDocument, myPage, myPDFFile, bookletPages, startBookletPages){
switch (bookletPages) {
case 4 :
var a = [4,1,2,3];
break;
case 8 :
var a = [8,1,2,7,6,3,4,5];
break;
case 12 :
var a = [12,1,2,11,10,3,4,9,8,5,6,7];
break;
case 16 :
var a = [16,1,2,15,14,3,4,13,12,5,6,11,10,7,8,9];
break;
case 20 :
var a = [20,1,2,19,18,3,4,17,16,5,6,15,14,7,8,13,12,9,10,11];
break;
case 24 :
var a = [24,1,2,23,22,3,4,21,20,5,6,19,18,7,8,17,16,9,10,15,14,11,12,13];
break;
case 28 :
var a = [28,1,2,27,26,3,4,25,24,5,6,23,22,7,8,21,20,9,10,19,18,11,12,17,16,13,14,15];
break;
case 32 :
var a = [32,1,2,31,30,3,4,29,28,5,6,27,26,7,8,25,24,9,10,23,22,11,12,21,20,13,14,19,18,15,16,17];
break;
case 36 :
var a = [36,1,2,35,34,3,4,33,32,5,6,31,30,7,8,29,28,9,10,27,26,11,12,25,24,13,14,23,22,15,16,21,20,17,18,19];
break;
case 40 :
var a = [40,1,2,39,38,3,4,37,36,5,6,35,34,7,8,33,32,9,10,31,30,11,12,29,28,13,14,27,26,15,16,25,24,17,18,23,22,19,20,21];
break;
}
var i = 0;
var finishPage = +startBookletPages +bookletPages;
var myPDFPage;
app.pdfPlacePreferences.pdfCrop = PDFCrop.cropPDF;
var myCounter = 1;
var myBreak = false;
while(myBreak == false){
if(myCounter > 2 && (myCounter & 1)){
myPage = myDocument.pages.add(LocationOptions.after, myPage);
}
app.pdfPlacePreferences.pageNumber = a[i]+startBookletPages;
if (myCounter & 1)
myPDFPage = myPage.place(File(myPDFFile), [0,0])[0];
else
myPDFPage = myPage.place(File(myPDFFile), [app.activeDocument.documentPreferences.pageWidth/2,0])[0];
if(myCounter == 1){
var myFirstPage = finishPage;
}
else{
if(i == a.length-1){
//myPage.remove();
myBreak = true;
}
}
myCounter = myCounter + 1;
i++;
}
}