Auto data merge several csv files and save pdf with a specific preset
Hello, I need to merge data from a lot of csv files and export every file with a specific pdf preset.
I have:
• A folder named "Csv" with all the csv files
• An indesign file named "Template.indd" ready for data merge and linked to the first csv file inside the folder.
• A folder named "Print files" for pdf exports
• A folder named "Union files" for inDesign merged documents
I need to:
1. update data (with the Template.indd file for data merge already opened)
2. create the data merged document
3. export the pdf file using the pdf export preset named "calendarmerge" in the "Print files" folder using the csv name for the file
4. save the inDesign file into the "Union files" folder using the csv name for the file
5. close merged document
6. update data source on the main file using the next csv file and repeat the process for every csv file in the folder
I've found this script that should work but i need to add some lines to adapt it to my needs.
Could someone help me, please?
// templateFile path
var myTemplate = File ("~/Desktop/_templates/Template_01.indt");
app.open(myTemplate);
// OutputFolder path
var myOutputfolder = Folder ("~/Desktop/_folderOut/");
// TxtFolder path
var myTxtFolder = Folder ( "~/Desktop/_txt/" );
if ( myTxtFolder != null ) {
var myTxtFiles = [];
var myAllTxtFilesList = myTxtFolder.getFiles();
for (var f = 0; f < myAllTxtFilesList.length; f++) {
var myFile = myAllTxtFilesList;
if (myFile instanceof File && myFile.name.match(/\.txt$/i)) {
myTxtFiles.push(myFile);
// merge and record data
app.activeDocument.dataMergeProperties.selectDataSource(myFile);
app.activeDocument.dataMergeProperties.mergeRecords();
// set the OutputFolder and fileExtension to ".indd"
var mySavedDocument = Folder (myOutputfolder + new File (myFile.name.replace(/\.txt$/i, ".indd")));
// save the file
app.activeDocument.save(mySavedDocument);
// close the file
app.activeDocument.close();
}
}
}