forked from GitBruno/Novelty
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathExport_Multiple_PDF.jsx
More file actions
executable file
·146 lines (128 loc) · 3.98 KB
/
Export_Multiple_PDF.jsx
File metadata and controls
executable file
·146 lines (128 loc) · 3.98 KB
1
//Export_Multiple_PDF.jsx//An InDesign CS5 JavaScript//Bruno Herfst 2010//Print multiple PDFs with presetscover for covers made with coverbuilder#target InDesign;try { //global vars var PDFcount = 2; var myPDFfrontCover=new Array(); var myPDFExport=new Array(); var myPreset = new Array(); var myCVR1 = new Array(); var myDocument = app.activeDocument; var myDocumentName = seperate(myDocument.name,false); var myPresets = app.pdfExportPresets.everyItem().name; myPresets.unshift("- Select Preset -"); makePDF(myDocument,PDFcount);} catch(err) { var txt=err.description; alert(txt); exit();}//////////////////////// F U N C T I O N S ///////////////////////////////////////////////function seperate(myFileName,extension) { if (extension == true){ return myFileName.replace(/^.*\./,''); } else { return myFileName.replace(/.[^.]+$/,''); }}function makePDF(myDocument,amount){ myCounter = 0; myPDFExport=[]; myPDFfrontCover=[]; var myWin = new Window('dialog', 'Export '+amount+' PDFs'); myWin.orientation = 'column'; myWin.btnAdd = myWin.add('button', undefined, '+'); myWin.btnRem = myWin.add('button', undefined, '-'); for (var i=0; i<amount; i++) { myPDFExport[i] = myWin.add('dropdownlist',[0,0,250,20],undefined,{items:myPresets}); myPDFExport[i].selection = 0; myPDFfrontCover[i] = myWin.add('dropdownlist',[0,0,250,20],undefined,{items:["All","CVR1"]}); myPDFfrontCover[i].selection = 0; myCounter++; } myWin.btnC = myWin.add('button', undefined, 'Cancel'); myWin.btnOK = myWin.add('button', undefined, 'OK'); //button functionality myWin.btnC.onClick = function () { myWin.close(0); }; myWin.btnOK.onClick = function () { myWin.close(1); }; myWin.btnAdd.onClick = function () { myWin.close(2); }; myWin.btnRem.onClick = function () { myWin.close(3); }; myWin.center(); var myWindow = myWin.show(); if(myWindow == 1){ // OK for(var i=0; i<myCounter; i++){ //check presets if(String(myPDFExport[i].selection) == "- Select Preset -"){ myPreset[i] = false; } else { myPreset[i] = String(myPDFExport[i].selection); } //check page Setting if(String(myPDFfrontCover[i].selection) == "CVR1"){ myCVR1[i] = true; } else { myCVR1[i] = false; } } exportPDFs(); }else if(myWindow == 2){ // ADD resetWin(true) }else if(myWindow == 3){ // SUBTRACT resetWin(false) }else{ /* Cancel */ }}function resetWin(add){ if(add == true){ PDFcount +=1; }else{ PDFcount -=1; if(PDFcount < 1){ PDFcount =1; } } makePDF(myDocument,PDFcount);}function stripFileName(myString){ s = myString.replace(/[:\\\/\*\?\"\'<>|]/g,""); return s;}function exportPDFs(){ //get the export location var myFolder = Folder.selectDialog ("Choose a Folder to save PDF"); if(myFolder != null){ //do all presets for(var i=0; i<myPreset.length; i++){ app.pdfExportPreferences.exportReaderSpreads=false; if(myPreset[i] == false){ alert("Did not output PDF No "+i+"\nNo preset selected"); }else{ var myExportPreset = app.pdfExportPresets.item(myPreset[i]); var myPresetName = stripFileName(myPreset[i]); if(myCVR1[i] == true){ if(myDocumentName.match(/CVR/g)){ myDocumentName = myDocumentName.replace(/CVR/g,"CVR1"); var myFilePath = myFolder + "/" + myDocumentName + myPresetName + ".pdf"; }else{ var myFilePath = myFolder + "/" + myDocumentName + "_CVR1_" + myPresetName + ".pdf"; } //export front cover only app.pdfExportPreferences.pageRange="3"; app.pdfExportPreferences.exportReaderSpreads=false; }else{ //export all pages app.pdfExportPreferences.pageRange="All"; app.pdfExportPreferences.exportReaderSpreads=true; var myFilePath = myFolder + "/" + myDocumentName + "_CVR_" + myPresetName + ".pdf"; } // Let’s start exporting var myFile = new File(myFilePath); myDocument.exportFile(ExportFormat.PDF_TYPE, File(myFile), false, myExportPreset); } }//end do all presets }else{ alert("No location selected"); }}