11 Replies Latest reply on Jan 23, 2011 9:07 AM by mrdior

    Generating single PDFs with data merge...

    mrdior Level 1

      Per this link, I've successfully learned how to use data merge to generate a single merged document with one page per record from a CSV file. But does anyone know the best way to export each page as its own PDF from ID?

        • 1. Re: Generating single PDFs with data merge...
          mrdior Level 1

          Please correct me if I'm wrong, but it seems that the only way to export the pages resulting from a data merge as individual PDF files is to do it programmatically. I've searched the forum and I've turned up the following code:

           

          for (i=0; i<app.activeDocument.pages.length; i++)

          {

            var myID = app.activeDocument.pages[i].textFrames.item("id").contents;

            var myPath = "/d/pdf_output/";

            var myFilename = new File(myPath + myID + ".pdf");

            app.activeDocument.exportFile(ExportFormat.pdfType,myFilename, false);

          }

           

          I can understand the code snippet well enough but I don't know how to package and invoke it. Would someone be able to help me figure that out under Mac OS X?

           

          B

          • 2. Re: Generating single PDFs with data merge...
            [Jongware]-9BC6tI Level 4

            This code is a Javascript. Start the ESTK Editor (it should be installed along with your InDesign), copy the "this is obviously the script itself and not any comments" bit, and paste into a new document. Then save in your InDesign User Scripts folder, under any name that you think you can remember, as long as it ends with .jsx

             

            More information on this: http://indesignsecrets.com/how-to-install-scripts-in-indesign.php

            1 person found this helpful
            • 3. Re: Generating single PDFs with data merge...
              [Jongware]-9BC6tI Level 4

              By the way, nowhere in that script is a page range mentioned. As I understand it, it will export the entire document, once for each page in that document -- for a 30 pg document, you will end up with 30 documents, each 30 pages long.

               

              Use Google; how to export documents to single-page PDFs has come up before.

              1 person found this helpful
              • 4. Re: Generating single PDFs with data merge...
                mrdior Level 1

                Thanks. Stepping through the process of learning how to use the ExtendScript Toolkit... and thanks for the tip about defining a page range. So far I've found this line of code...

                 

                app.pdfExportPreferences.pageRange = ...

                 

                and I'm assuming my value is 1 but I'm not sure it works that way. Maybe I have to increment something for each save so I get one PDF per page of the source ID document. Checking...

                • 5. Re: Generating single PDFs with data merge...
                  mrdior Level 1

                  aah. i found this great post... now to give 'er a try...

                  • 6. Re: Generating single PDFs with data merge...
                    mrdior Level 1

                    Thanks again for your help Jongware in pointing me in the right direction. Together with that post, I've adapted the script to save the single PDFs in a folder of my choosing.

                     

                    I need to change how the filename is constructed for each page in the (source) data merged document... and I'd like to reference a text frame or two to do that. But I got an error when I added 'myID' to the file name. Is the problem that the text frame variable name <<id>> is no longer available in the merged document?? How can I reference that field?

                     

                    Here's the code I adapted from Shonky...

                     

                    //ExportEachPageAsPDF.jsx
                    //An InDesign CS4 JavaScript
                    //
                    //Exports each page of an InDesign CS document as a separate PDF to 
                    //a selected folder using the current PDF export settings.
                    //Display a "choose folder" dialog box.
                    
                    main();
                    
                    function main() {
                        mySnippet();
                    }
                    
                    function mySnippet() {
                         //<fragment>
                         var myPageName, myFilePath, myFile;
                         var myDocument = app.activeDocument;
                         var myPath = "/Users/Shared/GD/Ventures/RM/Shop/Docs/output/";
                         var myPDFExportPreset = app.pdfExportPresets.item("[Press Quality]");
                         for(var i = 0; i < myDocument.pages.length; i++){
                              var myID = app.activeDocument.pages[i].textFrames.item("id").contents;
                              myPageName = myDocument.pages.item(i).name;
                              app.pdfExportPreferences.pageRange = myPageName;
                              //The name of the exported files will be the base name + the 
                              //page name + ".pdf". If the page name contains a colon (as it will 
                              //if the document contains sections), then remove the colon.
                              var myRegExp = /:/gi;
                              myPageName = myPageName.replace(myRegExp, "_");
                              myFilePath = myPath + myID + "_" + myPageName + ".pdf";
                              myFile = new File(myFilePath);
                              myDocument.exportFile(ExportFormat.pdfType, myFile, false, myPDFExportPreset);
                         }
                    }
                    
                    
                    
                    • 7. Re: Generating single PDFs with data merge...
                      mrdior Level 1

                      This post seems to imply that I'd have to manually go page by page through the resultant data merged document and "tag the boxes with the ID element by using its label property." That seems like a particularly onerous solution, especially if I have a lot of pages.

                       

                      Is there a way to reference the textframe (text frame) that was <<id>> before I executed the data merge??

                      • 8. Re: Generating single PDFs with data merge...
                        mrdior Level 1

                        The post i was referring to ... is here.

                        • 9. Re: Generating single PDFs with data merge...
                          [Jongware]-9BC6tI Level 4

                          I don't know squat about Data Merge -- does this use a single template file? If so, you would tag the (one and only, presumably) text frame in that with "id".

                          Call up the Script Label panel, click on your text frame to select it, and enter the id "id" into the Script Label text box. Don't press Return, 'cause that will get added to the script label as well ... instead, use Tab to 'leave' the Script Label Text Box.

                           

                          Note that this does not work with CS5 -- the entire label system was reviewed and changed. If you are on CS5 I'd happily refer you back to the numerous previous discussions on that ...

                          • 10. Re: Generating single PDFs with data merge...
                            mrdior Level 1

                            Roger that re. Data Merge. Yes, there is a single template .indd file that I use Data Merge on. However, the resultant merged file has numerous text frames... so I'll guess I'll have to iterate (like in this post) over the text frames until I find the one labeled 'id'.

                             

                            Thanks for the tips re. using the Script Label panel. And, no, I'm in CS4. I'll definitely take a look at the CS5 caveats bc we may upgrade at some point.

                             

                            I wonder if I were to label that text frame prior to Data Merge if the label would be present on each of the resultant data merged pages... ? Hmm...

                            • 11. Re: Generating single PDFs with data merge...
                              mrdior Level 1

                              The answer is YES. If I label the text frame as 'id' in the Script Label panel the data merged file reflects that on each page! Thank goodness!!