I’m looking to automate data merge to create multiple PDFs per row of data (each PDF would have 10 pages) and with each PDF being named uniquely based on a column in the data.


  • InDesign document with multiple pages (10 pages).
  • CSV with 100 people.
  • I want to have a PDF for each person (100 pdfs).
  • Each PDF will be a 10 page document for that person.
  • Filename for each PDF should contain a single person’s name; to know which PDF to send to which person (report_john_doe.pdf).

Roadblocks I’m hitting:

  • Data Merge that generates multiple InDesign docs; great but how do I automate them to then export to PDF + uniquely name the file based on a row/columns from the CSV?
  • Data Merge to Export PDF; this creates one PDF with every person in it.


  • InDesign CS6
  • Acrobat Pro

I’ve searched around on the forums but it has been a bear to figure it out. Old scripts, 404 pages, certain functionality missing, and no step by step walkthrough to figure out how to use said script.

Found this script but not sure how to set it up + use it.... ? http://forums.adobe.com/message/5551746#5551746

What’s the best path to automate this via a combination of Data Merge, Scripts, Actions as necessary?

Thanks for any help!


  • Looks like the linked script might work. I think if you copy it with a text editor, save is as a .jsx file, and place it in your Indesign scripts folder (use the Javascript one) it could be tested.
    – Rsiel
    Commented Apr 11, 2014 at 20:02
  • Looks like it's a script for Acrobat. I can't actually test it on this machine.
    – Rsiel
    Commented Apr 11, 2014 at 20:09

2 Answers 2


The workflow this script is set up for is the Data Merge >> Export PDF, which as you noted spits out a single, massive PDF.

The script runs in Acrobat. It takes the CSV file as an input (said CSV must have a column named "filename" containing the individual name for the extracted PDF. It counts the total number of pages in the PDF and divides by the total number of records in the CSV in order to calculate the number of pages per individual PDF, then iterates through the document, extracting pages as it goes.

There is user input for text to prefix and/or suffix the output file names.

I've not tested this, but it looks straightforward (other than the parsing of the CSV, which came from someone on stackoverflow and I didn't look over in detail).

For the record, here is the script:

var CSV = function (data, delimiter) {
var _data = CSVToArray(data, delimiter);
var _head = _data.shift();
return {
    length: function () {return _data.length;}, 
    adjustedLength: function () {return _data.length - 1;}, 
    getRow: function (row) {return _data[row];}, 
    getRowAndColumn: function (row, col) {
        if (typeof col !== "string") {
            return _data[row][col];
        } else {
            col = col.toLowerCase();
            for (var i in _head) {
                if (_head[i].toLowerCase() === col) {
                    return _data[row][i];
function CSVToArray( strData, strDelimiter ){
    strDelimiter = (strDelimiter || ",");
    var objPattern = new RegExp(
            // Delimiters.
            "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
            // Quoted fields.
            "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
            // Standard fields.
            "([^\"\\" + strDelimiter + "\\r\\n]*))"
var arrData = [[]];
var arrMatches = null;
while (arrMatches = objPattern.exec( strData )){
    var strMatchedDelimiter = arrMatches[ 1 ];
    if (
        strMatchedDelimiter.length &&
        (strMatchedDelimiter != strDelimiter)
        arrData.push( [] );
    if (arrMatches[ 2 ]){
        var strMatchedValue = arrMatches[ 2 ].replace(
            new RegExp( "\"\"", "g" ),
    } else {
        var strMatchedValue = arrMatches[ 3 ];
    arrData[ arrData.length - 1 ].push( strMatchedValue );
return( arrData );

function isInt(n) {
    return typeof n === "number" && n % 1 == 0;

var prepend = app.response("Enter any text to go at the START of each filename:");
var append = app.response("Enter any text to go at the END of each filename:");
var pathStr = app.response("If the PDFs should be saved in a sub folder, enter the relative path here:", "", "pdf/");

this.importDataObject("CSV Data");
var dataObject = this.getDataObjectContents("CSV Data");
var csvData = new CSV(util.stringFromStream(dataObject, 'utf-8'), ',');
var pagesPerRecord = this.numPages / csvData.length();
if (isInt(pagesPerRecord)) {
    for (var i = 0; i < this.numPages; i ++) {
        var pageStart = i*pagesPerRecord;
        var pageEnd = (i+1)*pagesPerRecord - 1;
        var recordIndex = (i + pagesPerRecord) / pagesPerRecord;
        var filename = csvData.getRowAndColumn(i, "filename");
        if (!filename) {
            app.alert('No filenames found - using "file-XX.pdf". Press Escape after continuing to cancel.');
            filename = "file-" + i;
        var settings = {nStart: pageStart, nEnd: pageEnd, cPath: pathStr+prepend+filename+append+'.pdf'};
} else {
    var message = "The number of pages per row is not an integer (" + pagesPerRecord;
    message += ", " + this.numPages + " pages, " + csvData.length() + " rows).";
  • hi there, as someone with limited experience with scripting, how do I run a script in acrobat reader? Or do I have to run this on in InDesign?
    – CrazyQwert
    Commented Mar 17, 2018 at 14:01

A colleague of mine ended up creating a custom python script. Using that python script and the batch_convert.jsxbin InDesign script we're now able to automatically generate each PDF, uniquely named based on the CSV data.

Our python script and an example is available here. https://github.com/goinvo/Batch-IDML-Generator

The batch_convert.jsxbin script is available here. http://www.kahrel.plus.com/indesign/batch_convert.html This will take all the IDMLs generated from the python script and then automatically convert them into PDFs.


  1. Verify python file has the right IDML path and CSV path.

  2. Open Terminal and ‘cd' to the directory containing the IDML, CSV, and python script.

  3. In Terminal, enter 'python3 batch_idml_editor.py' (success = Terminal prints out each patient file, failure = Terminal displays error).

  4. Open InDesign with no open files.

  5. In InDesign, run script ‘batch_convert.jsxbin'

  6. From the batch_convert.jsxbin popup, select your ‘Input Folder'. This will be the folder generated by your python script from step 3. It’ll look like ‘outputXXXXXXX’.

  7. From the batch_convert.jsxbin popup, select your 'Output Folder'. This is the directory where you want the PDFs to be placed. Pick anything that makes sense.

  8. From the batch_convert.jsxbin popup, select ‘Source Format’ = ‘IDML’.

  9. From the batch_convert.jsxbin popup, click ‘OK’ button. This will generate all the PDFs and should be complete within a few minutes.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.