4 Replies Latest reply on Jul 16, 2015 3:54 PM by prifreire

    [JS CS3 WIN] ExportEachPageAsPDF

    cwenet

      Hello,

       

      I have found this script. Now I want to modify the filename section.

       

      //ExportEachPageAsPDF.js  
      //Exports each page of an InDesign CS document as a separate PDF to  
      //a selected folder using the selected PDF export settings.  
      //Display a "choose folder" dialog box.  
      if(app.documents.length != 0){  
          var myFolder = Folder.selectDialog ("Choose a Folder");  
          if(myFolder != null){  
              myExportPages(myFolder);  
          }  
      }  
      else{  
          alert("Please open a document and try again.");  
      }  
      function myExportPages(myFolder){  
          var myPageName, myFilePath, myFile;  
          var myDocument = app.activeDocument;  
          var myDocumentName = myDocument.name;  
          var myPDFPresets = app.pdfExportPresets;
          var myPDFPresetNames = new Array;
          for (i = 0; i < myPDFPresets.length; i++)
              myPDFPresetNames.push(myPDFPresets[i].name); 

          var myDialog = app.dialogs.add();  
          with(myDialog.dialogColumns.add()){ 
              with(dialogRows.add()){   
                  with(dialogColumns.add()) {
                      staticTexts.add({staticLabel:"Base name:", minWidth:130});  
                  }
                  with(dialogColumns.add()) {
                      var myBaseNameField = textEditboxes.add({editContents:myDocumentName,   minWidth:160});  
                  }
              }  
              with(dialogRows.add()){ 
                  with(dialogColumns.add()){ 
                      staticTexts.add({staticLabel:"PDF preset: ", minWidth:130}); 
                  } 
                  with(dialogColumns.add()){ 
                      var myPDFPresetsDropdown = dropdowns.add({stringList:myPDFPresetNames,  selectedIndex:0}); 
                  } 
              } 
          }
          var myResult = myDialog.show({name:"ExportPages"});  
          if(myResult == true){  
              var myBaseName = myBaseNameField.editContents;  
              var myPDFPresetName = myPDFPresetNames[myPDFPresetsDropdown.selectedIndex];
              //Remove the dialog box from memory.  
              myDialog.destroy();  
              for(var myCounter = 0; myCounter < myDocument.pages.length; myCounter++){  
                  myPageName = myDocument.pages.item(myCounter).name;  
                  app.pdfExportPreferences.pageRange = myPageName; 

       

      //Generate a filename. /////////////////////////////
                app.findTextPreferences.appliedParagraphStyle = "picture_description"; 
                app.findTextPreferences.findWhat = '';
               
               myStory = myDocument.stories;
         
                myFound = myStory.findText();
               
             // alert(myFinds[0].contents);

       

                  myFilePath = myFolder + "/" + myFound[0].contents + ".pdf";  
                  myFile = new File(myFilePath);  
                  myDocument.exportFile(ExportFormat.pdfType,   myFile, false, myPDFPresets.item(myPDFPresetName)); 

      ///////////////////////


              }  
          }  
          else{  
              myDialog.destroy();  
          }  
      }

       

      On every page there is only 1 paragraph styled with the paragraphstyle "picture_description".

      I want to use the content of this paragraph for the filename for each page.

       

      please, can someone help me?

       

      Best regards

      Christoph