Iterate through a data source, exporting one document per record in the panel.
To install this script, navigate to the Adobe InDesign Application Directory and paste the script file into the following folder ‘Scripts -> Scripts Panel’. The script can then be run from the Scripts panel; this is found in ‘Window -> Utilities -> Scripts’.
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 | #target InDesign //EDIT THE VARIABLES BELOW BEFORE RUNNING SCRIPT var datasourceName = "ENTER NAME OF DATASOURCE HERE"; var docName = "NAME OF FIELD CONTAINING DOCUMENT NAMING INFORMATION"; //For example a category field var templateLocation = "PATH TO THE .INDT TEMPLATE FILE"; var scriptLabelName = "ENTER THE SCRIPT LABEL THAT REFERS TO THE PAGINATION TEXT FRAME"; var libraryLocation = "PATH TO THE LIBRARY FILE"; var outputLocation = "PATH TO OUTPUT LOCATION"; app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract; var myEC = app.easycatalogObject; var myDoc; if (myEC == null) { $.writeln("myEC is null"); } myDS = myEC.datasources.item(datasourceName); if (myDS != null) { var dvCount = myDS.dataviews.count(); for (index = dvCount-1; index >= 0; index--) { myDS.dataviews.item(index).closeDataView(); } var myDV = myDS.dataviews.add(); if (myDV != null) { var RowCount=myDV.rowCount; for (var i = 1; i <= RowCount; i++) { myDV.makeSelection(i,i); var myName = myDV.records.item(i-1).fields.item(docName).fieldContent; myDoc = app.open(File(templateLocation), true); if (myDoc != null) { var myInsertionPoint = myDoc.textFrames.item(scriptLabelName).insertionPoints[0]; myDV.paginateIntoTextFlow(myInsertionPoint, libraryLocation); var fileName = outputLocation; if (i < 10) fileName += "0"; fileName += i; fileName += " - "; fileName += myName; fileName += ".indd"; myDoc.save(new File(fileName)); } else { result =result + ("Error: Unable to open the source InDesign file " ); myDoc = null; } myDoc.close(); } myDV.closeDataView(); } } else { $.writeln("unable to open datasource"); myDoc = null; myEC = null; } |