1) The script below requires your .indd template to be placed in a folder called "Automation."
You'll need to replace the references in your javascript file to match your files location for both the template, and the .csv file.
2)The other requirement of this script is to label your text boxes in the .indd template file. You'll do this using Indesign's script label panel. It can be found under "Window>Automation>"
3) In the template file style your text frames and place them as you would like them on the page.
4) Open the Data Merge Panel in Indesign, and import your .csv file using the corner pulldown menu. In order to populate the data merge panel with text frame field references you have to import your csv.
5) The Data merge panel is now populated with your fields. Drag and drop the fields on your text frames. Save your template file as Auto.indd, and move on to step 6.
6) Copy the javascript file, and place it in your Indesign's scripts folder. This can be found in your application's sub folders. "Scripts/Scripts Panel" The file is pasted below. Just copy and paste it. Save it as a Javascript file using Adobe's ExtendScript Toolkit. (It comes with the creative Suite).
Below, is the javascript file:
UPDATED JULY 21, 2014:
main();
function main()
{
//Set document to open indesign doc, from a file dialog box. You must provide the template
var myDocument = app.open(File.openDialog( "Pick an indesign file template." ));
myDocument.dataMergeProperties.selectDataSource(File.openDialog("Select your .csv file for import. The Merge process can take some time...", "*.csv"));
myDocument.dataMergeProperties.mergeRecords();
//Set measurement units so units on place match layout
with(myDocument.viewPreferences){
//Measurement unit choices are:
//* MeasurementUnits.agates
//* MeasurementUnits.picas
//* MeasurementUnits.points
//* MeasurementUnits.inches
//* MeasurementUnits.inchesDecimal
//Set horizontal and vertical measurement units to inches.
horizontalMeasurementUnits = MeasurementUnits.inches;
verticalMeasurementUnits = MeasurementUnits.inches;
myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
}
//This Saves the document under a new name so the template is not destroyed.
app.activeDocument.save(File("specialdatamerge.indd"));
//This Closes the document, with an option to not save the .indd file used for the merge.
//This is a good idea so the original file is not destructed.
myDocument.close(SaveOptions.no);
//open the new document you just saved.
var newDoc = app.open(File("specialdatamerge.indd"));
//do something with the contents of a layer.
var PageLength = app.activeDocument.documentPreferences.pagesPerDocument;
for (i; i<= PageLength-1;i++)
{
//For example, grab a text LAYER labeled "ID" (Not a script label).
var id = newDoc.pages.item(i).textFrames.item("ID").contents;
alert(id);
}
}//End Main
function main()
{
//Set document to open indesign doc, from a file dialog box. You must provide the template
var myDocument = app.open(File.openDialog( "Pick an indesign file template." ));
myDocument.dataMergeProperties.selectDataSource(File.openDialog("Select your .csv file for import. The Merge process can take some time...", "*.csv"));
myDocument.dataMergeProperties.mergeRecords();
//Set measurement units so units on place match layout
with(myDocument.viewPreferences){
//Measurement unit choices are:
//* MeasurementUnits.agates
//* MeasurementUnits.picas
//* MeasurementUnits.points
//* MeasurementUnits.inches
//* MeasurementUnits.inchesDecimal
//Set horizontal and vertical measurement units to inches.
horizontalMeasurementUnits = MeasurementUnits.inches;
verticalMeasurementUnits = MeasurementUnits.inches;
myDocument.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;
}
//This Saves the document under a new name so the template is not destroyed.
app.activeDocument.save(File("specialdatamerge.indd"));
//This Closes the document, with an option to not save the .indd file used for the merge.
//This is a good idea so the original file is not destructed.
myDocument.close(SaveOptions.no);
//open the new document you just saved.
var newDoc = app.open(File("specialdatamerge.indd"));
//do something with the contents of a layer.
var PageLength = app.activeDocument.documentPreferences.pagesPerDocument;
for (i; i<= PageLength-1;i++)
{
//For example, grab a text LAYER labeled "ID" (Not a script label).
var id = newDoc.pages.item(i).textFrames.item("ID").contents;
alert(id);
}
}//End Main