20 Replies Latest reply on Apr 22, 2017 1:34 PM by veerr28307328

    Batch Data Merge

    Eugene Tyson Adobe Community Professional & MVP

      I have 36 documents, all with Data Merges from different databases.

       

      I need to export all these to PDF - does anyone know of a script or a way to batch export 36 documents and datamerge them?

       

      I can't see a way in the normal controls of InDesign, if anyone knows of a way via script or other I'd love to have this.

       

      Thanks

        • 1. Re: Batch Data Merge
          Obi-wan Kenobi Adobe Community Professional

          Hi Eugene,

           

          Do you mean:

          I have 36 ID docs

          I want to export the 36 ID docs to 36 pdf files

          I want to merge these 36 pdf files in one pdf file?

           

           

          • 2. Re: Batch Data Merge
            Eugene Tyson Adobe Community Professional & MVP

            Nope

             

            I have 36 InDesign Documents.

             

            36 Excel Sheets

             

            I want to Data Merge 36 excel sheets to 36 InDesign Documents.

             

            I have the merges setup, that is Excel 1 is linked to InDesign 1, Excel 2 is linked to InDesign 2, etc.

             

            I want to Data Merge 36 open documents to PDFS into a folder.

            • 3. Re: Batch Data Merge
              Colin Flashman Adobe Community Professional

              Your answer lies in several parts.

               

              1) The 36 indesign files need to all be in the same folder. The csv/txt files can be wherever you like.

              2) You need to run the batchconvert.jsx script from Peter Kahrel and choose the folder with the indesign files in it as input and output, overwrite existing files, source format indesign, target format indesign, and to run a script called dm.jsx

              Screen Shot 2015-07-07 at 4.19.09 am.png

              3) The key is in the dm.jsx that is shown below:

              if(app.documents.length != 0){
                      var myDoc = app.activeDocument;
                      app.dataMergeOptions.removeBlankLines = true;
                      var myDataFile = File.openDialog("Select a data file")
                      var myLocation = "YOUR FINISHED PDF FILE FOLDER LOCATION"
                      var myName = myDoc.name
                      var myExport = myLocation + myName +".pdf"
                      if(myDataFile != ""){
                              myDoc.dataMergeProperties.selectDataSource(myDataFile,);
                              myDoc.dataMergeProperties.exportFile(myExport, "[High Quality Print]", );
                      }
              
              }
              

              This script was originally written by Ole Kvern, so full credit goes to him, i've just modified it to export to a known location with the filename of the indesign file being merged.

               

              I've tested this on 3 indesign files in the same folder and it works each time. Catch is, there is still a prompt to fetch the relevant data file for each indesign file. However, that's the best you're going to get from me!

              • 4. Re: Batch Data Merge
                Eugene Tyson Adobe Community Professional & MVP

                Thanks CD, that's a great start. I'll give it a go!

                • 5. Re: Batch Data Merge
                  Eugene Tyson Adobe Community Professional & MVP

                  Getting an error on Line 4 when run DM directly.

                   

                  Getting error line 84 on Batch Convert when running the script.

                  • 6. Re: Batch Data Merge
                    Eugene Tyson Adobe Community Professional & MVP

                    Please mark this as closed as I have posted in the Scripting forums as a paying job.

                    • 7. Re: Batch Data Merge
                      Colin Flashman Adobe Community Professional

                      I originally had errors on line 84 of the batch convert script. It meant that within the DM script, the address of the location on the location to save the PDFs to was not correct (line 5 of my modded script).  perhaps try an address not far from the hard drive (not sure if you are using windows or mac os).

                      • 8. Re: Batch Data Merge
                        Eugene Tyson Adobe Community Professional & MVP

                        I'd prefer a more automated solution and willing to pay for it, I've posted in the scripting forum for this.

                         

                        Ideally, I'd like the script to automate the data merge from folders and subfolders to a specific output folder, I've already linked all the data merging.

                         

                        Thanks for trying to help, I'm clueless with this sort of thing.

                         

                        Using Mac.

                        • 9. Re: Batch Data Merge
                          Colin Flashman Adobe Community Professional

                          I've just managed to improve on the script so that there is no "select a data file" dialog that pops up. It means the document folder that contains the indesign files and the data would look like this:

                           

                          doca.indd

                          doca.indd.txt

                          docb.indd

                          docb.indd.txt

                          docc.indd

                          docc.indd.txt

                           

                          In this example, doca.indd uses the text file doca.indd.txt for the variable data file.

                           

                          Apart from that, the solution works the same way (use Peter Kahrel's batchconvert.jsx as in my earlier post), but the dm.jsx script that it calls upon now looks like this:

                           

                          if(app.documents.length != 0){

                                  var myDoc = app.activeDocument;

                                  var myName = myDoc.name

                                  var myLocation = "YOURFOLDERHERE"

                                  var myExport = myLocation + myName + ".pdf"

                                  var myImport = myLocation + myName + ".txt"

                                  var myDataFile = myImport

                                  app.dataMergeOptions.removeBlankLines = true;

                                  if(myDataFile != ""){

                                          myDoc.dataMergeProperties.selectDataSource(myDataFile,);

                                          myDoc.dataMergeProperties.exportFile(myExport, "[High Quality Print]", );

                                  }

                          }

                           

                          The difference is once the OK button is pressed in the batchconvert.jsx script, it will just go through all of the indesign files and output them to data merged PDFs into the same folder. If you want the PDFs in another location, change this line:

                                  var myExport = myLocation + myName + ".pdf"

                          to something else

                                  var myExport = "YOUREXPORTFOLDERLOCATION"

                           

                          I'm actually quite excited about this script because it makes barcoded mail campaigns much easier to output to the split PDFs required for printing.

                          • 10. Re: Batch Data Merge
                            Eugene Tyson Adobe Community Professional & MVP

                            Seems like a good solution.

                             

                            I am wondering if the .txt file already linked to the InDesign file can be used?

                            • 11. Re: Batch Data Merge
                              Eugene Tyson Adobe Community Professional & MVP

                              I don't understand the Yourfolderhere line?

                               

                              It's crashing on me and I've put in the folder name, "TEST".

                               

                              Is that right?

                              • 12. Re: Batch Data Merge
                                Eugene Tyson Adobe Community Professional & MVP

                                Keeps saying "^1 not found at line 83"

                                • 13. Re: Batch Data Merge
                                  Colin Flashman Adobe Community Professional

                                  OK, the name of the folder has to be a full structured folder name. I'd redacted it in my example, but in the actual script i'm using the mylocation line looked like this:

                                  var myLocation = "Macintosh HD:Users:colly:Desktop:in1folder:"

                                  So the above location referred to a folder called "in1folder" sitting on my desktop. Now I'm running a Mac OSX 10.9.5.

                                  If you make a folder on your desktop and want to reference it and are unsure how, Kris Coppieters of Rorohiko has a download that makes this simple: https://www.rorohiko.com/wordpress/downloads/showpaths/ - literally drag the folder you want to reference onto the icon and the app shows you how it needs to be typed.

                                  The folder also contained indesign files and text as so:

                                  Screen Shot 2015-07-07 at 10.59.34 pm.png

                                  now the files don't have to be named sequentially like I have them there, BUT the filename of the data being referenced by the indesign file MUST be the same as the indesign name with the .txt extension at the end like the sample shows.

                                  e.g.

                                  carrot.indd

                                  carrot.indd.txt

                                  watermelon.indd

                                  watermelon.indd.txt

                                   

                                  I also apologise if there is a delay between responses as I'm in Australia and I think there is a 10 hour time difference.

                                  • 14. Re: Batch Data Merge
                                    Eugene Tyson Adobe Community Professional & MVP

                                    I was using backslashes not full colons. I'll try again.

                                    • 15. Re: Batch Data Merge
                                      Eugene Tyson Adobe Community Professional & MVP

                                      Ok Progress

                                       

                                      But it goes through the batch of InDesign files, which it didn't do before but still getting

                                       

                                      "^1 not found at line 83"

                                      • 16. Re: Batch Data Merge
                                        Eugene Tyson Adobe Community Professional & MVP

                                        Ok got it - missing a colon at end of folder location!

                                         

                                        That's a great help and it's very quick! Awesome!

                                         

                                        Although, I have to change the input folder in the script each time, and rename all the datamerge text files... very quick and efficient!!!

                                        • 17. Re: Batch Data Merge
                                          Eugene Tyson Adobe Community Professional & MVP

                                          Aw, I broke it.

                                           

                                          I want to use PDFX1A Hub Setting for the pdf output option, but it broke the script...

                                          • 18. Re: Batch Data Merge
                                            Colin Flashman Adobe Community Professional

                                            If you want to change the PDF setting that is being used, this line has to be amended

                                             

                                                            myDoc.dataMergeProperties.exportFile(myExport, "[High Quality Print]", );

                                             

                                            At the moment, it is using a default setting [High Quality Print] (note that I have kept the square brackets as that is exactly how it is written in the export PDF dialog box).

                                             

                                            If you want to change it to a better default, you can use the following line:

                                             

                                                        myDoc.dataMergeProperties.exportFile(myExport, "[PDF/X-1a:2001]", );

                                             

                                            Otherwise if you are using a custom-one that didn't ship with InDesign (e.g. a setting  called Colins Export) then the line would appear like so:

                                             

                                                        myDoc.dataMergeProperties.exportFile(myExport, "Colins Export", );

                                             

                                            I hope this helps

                                            • 19. Re: Batch Data Merge
                                              Eugene Tyson Adobe Community Professional & MVP

                                              I got it working.

                                               

                                              But now the script only works with all documents open. Which isn't a big deal.

                                               

                                              It's quite confusing for me as I have to edit the dm.jsx for each output, but I have it working and managed to do my exports in 1 minute, rather than hours.

                                               

                                              Thanks for the help.

                                               

                                              I'll keep searching for a completely automatic method too.

                                              • 20. Re: Batch Data Merge
                                                veerr28307328

                                                How can i do the same to Export JPEG for each recordx. I succefully exported one single PDF.