-
1. Re: Data Merge in newest version of InDesign
Steve Werner Jun 12, 2012 6:11 AM (in response to GrahamHe)There are no changes in Data Merge in InDesign CS6.
-
2. Re: Data Merge in newest version of InDesign
GrahamHe Jun 12, 2012 7:02 AM (in response to Steve Werner)Thanks Steve.
-
3. Re: Data Merge in newest version of InDesign
Ben Frey Jun 12, 2012 8:15 AM (in response to Steve Werner)Have there been any changes to Data Merge since CS3?
-
4. Re: Data Merge in newest version of InDesign
cosmorochester Aug 9, 2012 4:54 AM (in response to GrahamHe)If you're getting 500 separate PDF files, you're doing something wrong. You should be able to save your Excel file (with graphic file references) in tab-delimited TXT format, attach it to your InDesign template through Merge function, complete your layout by dragging fields, then generate your catalog. Check the Indesign Help function. Columns should be your Field names.
-
5. Re: Data Merge in newest version of InDesign
Peter Spier Aug 9, 2012 5:43 AM (in response to cosmorochester)Cosmo,
Did you read the first post? The OP isn't getting separate PDFs, he WANTS separate PDFs and was hoping something had changed to allow it.
-
6. Re: Data Merge in newest version of InDesign
GrahamHe Aug 9, 2012 5:50 AM (in response to Peter Spier)Hi all,
one of the Multimedia guys here wrote a javascript that saves the pdf pages is seperate files and names them using a column from an Excel file. Works quite nicely and I could upload it here in case anyone is interested.
Graham
-
7. Re: Data Merge in newest version of InDesign
nctrts Aug 20, 2012 4:50 AM (in response to GrahamHe)Graham,
Please please do upload it to pastebin / here / similar, that would be immensely helpful.
-
8. Re: Data Merge in newest version of InDesign
GrahamHe Aug 20, 2012 5:29 AM (in response to nctrts)Here you go. If you run the script, it will ask which csv file to use for the naming, and where its says 'PartnerHQ_Id' in my script, replace that with the column name you want to use. Let me know if anything is unclear; I am not really a Javascript kind of guy ...
/* Put script title here */
var CSV = function(data) {
var _data = data.split('\r\n');for(var i in _data) {
if(_data[i].length > 0) {
console.println(i + ' ' + _data[i]);
_data[i] = _data[i].split(',');
}
}
var _head = _data.shift();return {
length: 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];
}
}
}
}
};
};this.importDataObject("CSV Data");
var dataObject = this.getDataObjectContents("CSV Data");var csvData = new CSV(util.stringFromStream(dataObject));
if(this.numPages != csvData.length()) {
app.alert("Number of pages & CSV row count inconsistent");
} else {
for(var i = 0; i < this.numPages; i++) {
this.extractPages({nStart: i, cPath: csvData.getRowAndColumn(i, 'PartnerHQ_Id') + '.pdf'});
}
} -
9. Re: Data Merge in newest version of InDesign
cdflash Aug 23, 2012 6:00 PM (in response to GrahamHe)not sure if it works in CS6 (am trying this in CS5.5 mac running OSX 10.5.8) but I get a dialog with:
Error 24
Error String: this.importDataObject is not a function
on line 37
anyone else tried this script yet?
-
10. Re: Data Merge in newest version of InDesign
cdflash Mar 19, 2013 6:06 AM (in response to cdflash)Finally on cs6 and have retested GrahamHe's script. Still has the same error in InDesign, but that is because this is NOT and indesign script - it's an ACROBAT script! The script is applied using the action wizard.
So this doesn't behave the way I thought, such as running the script directly from indesign. The file is still merged to a single multi-page PDF file, and then the script is run via the action wizard.
Had trouble getting the script to work initially via acrobat but I did amend the second line to read
var _data = data.split('\r'); and it worked a treat!
One warning: the names in the column selected to become the filenames need to be unique (such as a primary key) otherwise there is a risk of files overwriting each other.
colly
-
11. Re: Data Merge in newest version of InDesign
alanomaly Jul 30, 2013 10:44 AM (in response to cdflash)Here's an improved version of that script:
- It works for multiple pages per record rather than just one page per record (and it figures out how many, e.g. 500 pages and 100 records = 5 pages each). The only limitation is, each record must have the same number of pages.
- It works for UTF-8 csv files, so it doesn't just skip or screw up accented characters or other non-English characters. If you have problems, make sure you're saving UTF-8 csvs - these are the default for most things except Excel, but quite tricky in Excel, see some suggestions here http://stackoverflow.com/questions/4221176/excel-to-csv-with-utf8-encoding
- It allows you to specify text to go before and after each name, and a sub folder to put the PDFs in
- It can cope with csvs that have commas and quotes in the cells, using CSV parsing code from here http://stackoverflow.com/questions/1293147/javascript-code-to-parse-csv-data (this should work fine but CSVs are quite variable - if you have problems, try exporting the CSV from a different program, e.g. if it's coming from Excel, try exporting it from Google Docs or OpenOffice)
If you have trouble running it in Acrobat's Actions panel, try running it in the Javascript console instead. Hit ctrl-J or cmd-J, then enable the console. copy and paste the code in, select the code you just copied and pasted, and hit ENTER (not return! on Mac) to run the code.
In my testing, (700kb PDFs, 600 or so records, 6gb RAM Mac Pro) it's pretty darn fast. Everything else I'd tried takes hours and hours or dies mid way, this takes less than a minute. Reading the CSV is probably the slowest part, then it spits out PDFs at a rate of several a second. It seems to take maybe 5% as long as the data merge takes.
Here's the improved code:
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]*))" ), "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)."; } -
12. Re: Data Merge in newest version of InDesign
alanomaly Aug 27, 2013 10:17 AM (in response to alanomaly)It seems this script gets slower the more hyperlinks there are in the document:
- Document with 1100 pages and no hyperlinks: About one 2-page PDF a second, maybe slightly more. Not bad.
- Same document with 11 hyperlinks every 2 pages: About one 2-page PDF every two or three minutes. Hopeless, it would take more than 24 hours.
- Same document run through Optimise PDF aggressively reducing its file size by 70% and then through Save As Reduced Size PDF turning off all backwards compatibility: About one 2-page PDF every 24 seconds. Bad, needs to be left running for 3 and a half hours at the end of the working day.
In each case it's "Saving PDF..." that is the point the process struggles with. I don't know what it is about the addition of hyperlinks that makes the PDFs so slow to save.
I think it's maybe something to do with cross-reference tables - the final PDFs are 25% cross reference tables according to Optimise PDF's audit tool, and there are no cross references so I can only guess that this is the hyperlinks. Why so much data, I have no idea.
-
13. Re: Data Merge in newest version of InDesign
benjikayuk Dec 11, 2013 8:09 AM (in response to alanomaly)Thanks for posting your revised script, it would seem that it should do exactly what I require.
I think I've set it up correctly as an Action in Acrobat.
I have a 137 page PDF which I want to split into single page documents. I have a .csv file with a list of 137 unique IDs, which I would like Acrobat to use to name the individual files.
I run the action and get prompted to input anything to prefix and suffix the filename with, together with an option of a relative path.
I then get asked to choose a data file, so I choose my CSV list.
The script seems to run ok but I get no output.
I'm guessing at some point it should ask me for column name and also how many pages per file output??
Or do I need to edit that in the script first? If so, which are the parts to edit?
THanks in advance,
Ben
-
14. Re: Data Merge in newest version of InDesign
alanomaly Jan 17, 2014 4:25 AM (in response to benjikayuk)Hey Ben, sorry looks like I wasn't clear - the CSV file must contain a column headed "filename" (lowercase). It pretty much only uses that one column, so it can be a one column CSV. It's written into the code.
If you want it to be variable (e.g. if you get CSVs you can't edit), add a line around line 67 like:
var columnHeader = app.response("Enter the column header of the filename column in the CSV", "", "filename");
...then find/replace "filename" (including quotes) with columnHeader.
A few other tips:
- Make sure the order of rows in your CSV matches the order of the file you used to create your merged document!
- Make sure you UNTICK "Create tagged PDF" when exporting the PDF else everything goes massively slow. This is the cause of my puzzlement about hyperlinks in my last comment - hyperlinks are fine, but tagged documents go nuts.
- If it doesn't start merrily churning out PDFs, scroll down in the Acrobat console box. Sometimes it hides error messages right at the end of the code, the last place anyone would expect. "The number of pages per row is not an integer" means you have a mismatch between the number of rows in your CSV and the number of records in your PDF.
-
15. Re: Data Merge in newest version of InDesign
yvesha Feb 1, 2014 7:35 PM (in response to alanomaly)Hi,
hoping someone can help.
I have a 48 page document which I need to split into 8 documents. I have the excel spreadsheet with column headed "filename" with 8 file names.
When I select the data file to import after being asked to enter text at start of filename etc I see the message 'No filenames found - using "file-XX.pdf". Press Escape after continuing to cancel.'
and then the error -
RaiseError: The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.
Doc.extractPages:83:Console undefined:Exec
===> The file may be read-only, or another user may have it open. Please save the document with a different name or in a different folder.
file-0
I have checked the number of rows in the csv with the one which i created the merge in Indesign and it is the same. I have also tried usinh google docs spreadsheet but acrobat doesnt recognise the URL.
Thank you.
-
16. Re: Data Merge in newest version of InDesign
alanomaly Feb 4, 2014 5:12 AM (in response to yvesha)Sounds like you've got the CSV file open in Excel or something similar.
Certainly with Excel for Mac, it gets stroppy if the CSV file is open - Excel won't let the script read it. Not sure about any other programs but I imagine they're similar.
Make sure the CSV is closed before running the script. I find it works best to have an excel version and a CSV version, keeping the excel version open to make any edits and closing the CSV versions as soon as they're saved.
-
17. Re: Data Merge in newest version of InDesign
yvesha Feb 4, 2014 1:28 PM (in response to alanomaly)Thanks for your reply.
I tried with exitng Excel but the same problem occured.
-
18. Re: Data Merge in newest version of InDesign
yvesha Feb 4, 2014 10:44 PM (in response to alanomaly)Hi alanomaly,
I managed to get acrobat to read a csv which was created in officelibre(as you mentioned) but I just have one more issue.
I am getting the error message 'The number of pages per row is not an integer (5.454545454545454, 60 pages, 11 rows).' which makes me believe that it doesnt realise I have 6 page documents.
Thanking you in advance.
-
19. Re: Data Merge in newest version of InDesign
benwa02 Apr 11, 2014 11:38 AM (in response to alanomaly)How do I set this script/action up + execute it?
What does the process look like from CSV to InDesign to Acrobat to final PDF?
I'm slow!
-
20. Re: Data Merge in newest version of InDesign
TStanwood Jun 25, 2014 12:53 PM (in response to yvesha)Hi, Did you receive an answer to this issue? I get the same error:
The number of pages per row is not an integer (5.333333333333333, 16 pages, 3 rows).
How does the code know how many pages each document should be?
-
21. Re: Data Merge in newest version of InDesign
alanomaly Jun 26, 2014 3:50 AM (in response to TStanwood)If it's saying "'The number of pages per row is not an integer (5.454545454545454, 60 pages, 11 rows)" that means that the number of pages isn't divisible by the number of rows. So, yvesha has 60 pages and 11 rows, which means 5.4545 pages per row, which doesn't make sense, you can't have a PDF with 5.4545 pages. It sounds like you're aiming for 6 pages per row, which means there should be 10 rows in your CSV ( 60 / 10 = 6 ).
TStanwood has 16 pages and 3 rows, but 3 doesn't go into 16. This could mean there's too many pages in the Indesign file (maybe there's one extra page and it's supposed to be 3 five-page PDFs?) or the wrong number of rows in the CSV.
Sometimes Excel adds empty rows to CSVs for no reason other than wanting to ruin your day... if the number of rows the script says you have doesn't match the actual number of rows you're seeing in the CSV in Excel, open the CSV with a plain text editor and delete any empty lines of text.
-
22. Re: Data Merge in newest version of InDesign
TStanwood Jun 26, 2014 2:08 PM (in response to alanomaly)The issue is I have two rows, but it's counting the header row as one.
Todd
-
23. Re: Data Merge in newest version of InDesign
TStanwood Jun 26, 2014 2:15 PM (in response to alanomaly)Hi, thanks for responding. I only have two rows but it's counting the header row as one making it three. Todd
-
24. Re: Data Merge in newest version of InDesign
gsnevius812 Jul 21, 2014 10:02 AM (in response to GrahamHe)I am running into the same situation as well. I have tried a myriad of solutions, but nothing seems to work
I don't think that I am missing something that's fundamentally simple. I've gone through the process a couple of dozen times without success.
I may have to split my PDF and rename manually - bummer.
-
25. Re: Data Merge in newest version of InDesign
TStanwood Jul 21, 2014 10:09 AM (in response to gsnevius812)I'm going to purchase this Advanced Software for Splitting and Merging PDF Documents because I couldn't get the script to work.
-
26. Re: Data Merge in newest version of InDesign
RuthK Jul 22, 2014 9:18 AM (in response to GrahamHe)Hi Graham / everyone else
Did you ever figure out how to do this? I need to do a similar (or the same) task. I have a 12pp document and 100 records, I want to output 100 x 12pp PDF files, named from a column in the attached CSV.
Any ideas?
-
27. Re: Data Merge in newest version of InDesign
gsnevius812 Jul 22, 2014 9:31 AM (in response to RuthK)Hello Ruth!
I attempted it again today with a clear mind hoping that it was just something that I was missing or doing wrong. Unfortunately, I still was not able to successfully execute the process. I'm not sure if it's the JavaScript or the CSV file. If I had to guess, I would say that based on the complexity of the JavaScript, it's not counting the lines in the database properly. I've done everything possible to - and with the CSV file and end up with the same "The number of pages per row is not an integer…" error. I have a 597 page PDF that I need to split into 199, 3-page PDFs and rename. I really would hate to do this manually, but I have spent so much time trying to get the script to work that I could have . I cannot afford to purchase any software that might be available to accomplish this same thing. Should you manage to find a usable solution, please do share. I know that I would greatly appreciate it!
Best of luck!
-
28. Re: Data Merge in newest version of InDesign
RuthK Jul 22, 2014 9:40 AM (in response to gsnevius812)I can't even get my head around the script
In Acrobat Pro you can automatically split the document into even sized "parts" - but you still need to manually rename which I'm hoping to avoid.
Pages > Split Document
If that helps.
-
29. Re: Data Merge in newest version of InDesign
gsnevius812 Jul 22, 2014 9:50 AM (in response to RuthK)I hear you there! I can easily edit and break the script .
Yep, I can use that feature since my document can be split in groups of 3 pages. It's that darn renaming that's going to be the bane of my existence . And I know that as soon as I do rename manually, I'll get a change from someone that's going to require me to repeat the process all over again! So you see, I desperately need to automate this as much as possible. I'm sure you can relate .
Thank you for the suggestion!
-
30. Re: Data Merge in newest version of InDesign
RuthK Jul 22, 2014 9:55 AM (in response to gsnevius812)Absolutely, same problem here. I'll keep looking, maybe we can find a script to rename based on data, like first word in file? Then we can include it as a hidden field?
-
31. Re: Data Merge in newest version of InDesign
gsnevius812 Jul 22, 2014 10:09 AM (in response to RuthK)Sounds like a plan! I'm going to keep at it as time permits. I'm not in a major crunch yet, but this PDF I am working on will need to go out in about 2 weeks.
Thanks!!!
-
32. Re: Data Merge in newest version of InDesign
gsnevius812 Jul 23, 2014 11:01 AM (in response to gsnevius812)I have a workaround for this! I took my 597 page PDF and used the "Split" feature to break the PDF into 199, 3-page PDFs. Acrobat Professional will add numerals to the end of the resulting filenames as part of the split process. For example:
Filename_01.pdf
Filename_02.pdf
Filename_03.pdf
Since I had a CSV of the client names that I used in my data merge in InDesign, I created another column in Excel next to it. I copied the filename (omit the .pdf extension) of the first sequential PDF into the first cell of the second column and using the Auto Fill Option, (selecting "Fill Series") populated the column. My worksheet now contained two columns, the original name from the resulting Split PDF function, and a second column with the client name I used from the data merge.
I downloaded Advanced Renamer (Advanced Renamer - Free and fast batch rename utility for files and folders) and once working through getting familiar with its inner-workings, was able to batch rename all of my files. It's a free app, BTW. I was able to figure it out in just a couple of minutes and I'm pretty stupid .
What really helped me in this case was having the client names (199 in total) in Excel, so that eliminated a lot of work for me. If I do need to make changes to the original PDF and re-run the data merge feature, at least I have a process that is repeatable and won't require me to do anything manually. Whew!
Let me know if you have any questions and if you decided to go this route, let me know how you make out.
Good luck!
-
33. Re: Data Merge in newest version of InDesign
TStanwood Jul 23, 2014 11:23 AM (in response to gsnevius812)Thanks gsnevius812. I know how hard and long you worked on this. I spent many hours over many days and wasn't able to find a solution. Thanks again.
-
34. Re: Data Merge in newest version of InDesign
gsnevius812 Jul 23, 2014 11:32 AM (in response to TStanwood)Ah, no need to thank me! But thank you for your efforts as well.
I was determined to find a way and t's not the most streamlined process. However, it does work, so I'll stick with it -- or at least until Adobe implements this functionality directly into either InDesign or Acrobat. Consider this a feature request guys!
Take care!
-
35. Re: Data Merge in newest version of InDesign
RuthK Jul 23, 2014 11:42 AM (in response to GrahamHe)Ahhhhh well done!! I shall try this and let you know how it works out. Thanks for all your hard work. I completely agree, this really could be implemented directly within inDesign but till will attempt this and thank you for your efforts.
All my client names are already in excel too so similar structure I think. Here's hoping.




