9 Replies Latest reply on Oct 14, 2010 9:53 PM by Pontus Uggla

    Exporting to filename from paragraph style

    Derek Brown GA Comm

      I have a 80 page indesign file.  I would like to export to single page pdfs, with filenames based off a paragraph style on each page.

       

      Is this possible?  I have no background or experience with scripting.  Any help would be much appreciated.

       

      Thanks

      Derek

        • 1. Re: Exporting to filename from paragraph style
          Pontus Uggla Level 1

          Yes, it is posible, probably not even hard.

           

          How exactly are the paragraph styles named or what rules do you have? Do you have 80 paragraph styles, one per page or how is it set up?

          • 2. Re: Exporting to filename from paragraph style
            Derek Brown GA Comm Level 1

            It is a recipe book, one recipe per page.  The recipe names are all a paragraph style "Recipe Name".  I want single page pdfs named the Recipe Name.

            • 3. Re: Exporting to filename from paragraph style
              Pontus Uggla Level 1

              I see.

               

              1. Loop the pages.

              2. Search for text frames on each page.

              3. See if it contains the paragraph style, im assuming its the first paragraph of that text frame.

              4. Export the page using that name.

               

              for(var p = 0; p < app.documents[0].pages.length; p++) {
                   var frames = app.documents[0].pages[p].textFrames;
                   var page_name = null;
              
                   for(var i = 0; i < frames.length; i++) {
                        if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'test') {
                             page_name = frames[i].paragraphs[0].contents;
                             break;
                        }
                   }
              
                   if(page_name != null) {
                        // Export page
                   }
              }
              

              • 4. Re: Exporting to filename from paragraph style
                Derek Brown GA Comm Level 1

                Thanks so much for your help. However, I don't know what to do with this info.  Can you explain this to me in more "baby" steps?

                • 5. Re: Exporting to filename from paragraph style
                  Pontus Uggla Level 1

                  Allright, baby steps it is!

                   

                  You need a text editor, anything that can edit text without adding format. Word will not work, notepad will.

                   

                  I use a mac and I use TextMate since I use it for my websites.

                   

                  Adobe ships InDesign with the editor ExtendScript Toolkit (ESTK) that you will find on your computer. There is nothing really wrong with it, but i think TextMate is better.

                   

                  The language is an extension of Javascript called Extendscript. You can use the file ending .js or .jsx.

                   

                  Indesign is called just app, the documents of InDesign are called app.documents, the active document is called app.documents[0] etc.

                   

                  You put the scripts in the folder (Mac) /Applications/InDesign CS5/Scripts/Scripts Panel/

                   

                  In InDesign Vindow > Automation > Scripts or something like that, you will find a window with the scripts. Here you double click the script to run it.

                   

                  Start by putting alert('Hello world'); in a script to see that it is working.

                  • 6. Re: Exporting to filename from paragraph style
                    Derek Brown GA Comm Level 1

                    Do I need to change anything in the script?  I imported it into indesign, opened my file, ran the script, nothing happened.

                    • 7. Re: Exporting to filename from paragraph style
                      Pontus Uggla Level 1

                      The thing you really needed is not there.

                       

                      I just wrote "// export your page" since im lazy.

                       

                      What i showed was how to find the text, not how to export the page. The reason, I have never done it.

                       

                      If i get 5 minutes more i might find out and post for you.

                      • 9. Re: Exporting to filename from paragraph style
                        Pontus Uggla Level 1

                        The link you sent me was about Applescript. But I looked it up in the Javascript reference and this seems to work.

                         

                        You need to make three changes:

                         

                        Line 6: Change test to the name of your paragraph style.

                        Line 15: Change [Smallest File Size] to the export preference you like to use, so you get resolution, bleed etc correct.

                        Line 19: Change export path, I exported mine to my root, my harddrive, if you are on a pc "/c/cookbook/" + pdf_name + ".pdf" might be a better path.

                         

                         

                        for(var p = 0; p < app.documents[0].pages.length; p++) {
                             var frames = app.documents[0].pages[p].textFrames;
                             var pdf_name = null;
                        
                             for(var i = 0; i < frames.length; i++) {
                                  if(frames[i].paragraphs[0].appliedParagraphStyle.name == 'test') {
                                       pdf_name = frames[i].paragraphs[0].contents;
                                       break;
                                  }
                             }
                        
                             if(pdf_name != null) {
                                  app.pdfExportPreferences.pageRange = app.documents[0].pages[p].name;
                        
                                  var export_preset = app.pdfExportPresets.item("[Smallest File Size]");
                        
                                  app.documents[0].exportFile(
                                       ExportFormat.pdfType,
                                       File("/" + pdf_name + ".pdf"),
                                       false,
                                       export_preset
                                  );
                             }
                        }