Mobile app version of vmapp.org
Login or Join
Berumen635

: Data merge exports to multiple PDFs all uniquely named from data 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

@Berumen635

Posted in: #AdobeIndesign #DataMerge #Pdf

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.

Specs:


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.


Software:


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.... ? 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!

E

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Berumen635

2 Comments

Sorted by latest first Latest Oldest Best

 

@Berumen635

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. github.com/goinvo/Batch-IDML-Generator
The batch_convert.jsxbin script is available here. 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.

Steps:


Verify python file has the right IDML path and CSV path.
Open Terminal and ‘cd' to the directory containing the IDML, CSV, and python script.
In Terminal, enter 'python3 batch_idml_editor.py' (success = Terminal prints out each patient file, failure = Terminal displays error).
Open InDesign with no open files.
In InDesign, run script ‘batch_convert.jsxbin'
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’.
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.
From the batch_convert.jsxbin popup, select ‘Source Format’ = ‘IDML’.
From the batch_convert.jsxbin popup, click ‘OK’ button. This will generate all the PDFs and should be complete within a few minutes.


Done!

10% popularity Vote Up Vote Down


 

@Hamm6457569

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 + "rn]*))"
),
"gi"
);
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'};
this.extractPages(settings);
}
} else {
var message = "The number of pages per row is not an integer (" + pagesPerRecord;
message += ", " + this.numPages + " pages, " + csvData.length() + " rows).";
}

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme