2 Replies Latest reply on Mar 19, 2016 7:42 AM by beh_gras_beh

    Name PDF as Masterpage Name

    beh_gras_beh Level 1

      Dear Indesign scripters,

       

      I'm using this script for quite a while now. Thanks to Jongware.

      But is there an way I can name the PDF as the name of the master page it uses? (Like DocumentName+MasterpageNameA+MasterpageNameC.PDF)

      Exporting only selected master pages

       

      This is my edit from the original post above:

       

      var mCheckbox = [];  
      var expMasterDialog = app.dialogs.add({name:"Welke moeten geëxporteerd worden", canCancel:true});  
      with (expMasterDialog)  
      {  
      with(dialogColumns.add())  
      {  
        for (i=0; i<app.activeDocument.masterSpreads.length; i++)  
        {  
         with(dialogRows.add())  
         {  
          mCheckbox[i] = checkboxControls.add({staticLabel:app.activeDocument.masterSpreads[i].name,checkedState:false});  
         }  
        }  
      }  
      }  
      
      
      if (expMasterDialog.show() == true)  
      {
      newRange = '';  
      for (i=0; i<app.activeDocument.pages.length; i++)  
      {  
        if (app.activeDocument.pages[i].appliedMaster &&  
         mCheckbox[app.activeDocument.pages[i].appliedMaster.index].checkedState == true)  
        {  
        
        var myBaseName = app.activeDocument.pages[i].appliedMaster.name; 
        
         if (newRange) newRange += ',';  
         newRange += app.activeDocument.pages[i].name;  
        }  
      }  
      app.pdfExportPreferences.pageRange = newRange;  
      // alert (newRange);  
      
      
      
      
      
      
      app.activeDocument.exportFile (ExportFormat.PDF_TYPE, File((app.activeDocument.fullName.fsName +'_'+ myBaseName +'!').replace(/(\.indd)?!$/i, '.pdf')), true, app.pdfExportPresets[0]);  
      }  
      
      
      
      
      
      
      
      

      Thanks for anyone who wants to help me out.

        • 1. Re: Name PDF as Masterpage Name
          [Jongware] Most Valuable Participant

          Doesn't it already do so? Ah wait, I see it only uses the last seen master page name. I guess I was expecting you to use it with a single master page only.

           

          Fortunately, it's a small change only: construct the myBaseName prefix before looping over the individual pages, not 'inside' that loop.

           

          var mCheckbox = [];   
          var expMasterDialog = app.dialogs.add({name:"Welke moeten geëxporteerd worden", canCancel:true});   
          with (expMasterDialog)   
          {   
          with(dialogColumns.add())   
          {   
            for (i=0; i<app.activeDocument.masterSpreads.length; i++)   
            {   
             with(dialogRows.add())   
             {   
              mCheckbox[i] = checkboxControls.add({staticLabel:app.activeDocument.masterSpreads[i].name,checkedState:false});   
             }   
            }   
          }   
          }   
          
          
          if (expMasterDialog.show() == true)   
          {
              var myBaseName = '';
              for (i=0; i<app.activeDocument.masterSpreads.length; i++)
              {
              if (mCheckbox[i].checkedState == true)
              {
              if (myBaseName)
              myBaseName += '+';
              myBaseName += app.activeDocument.masterSpreads[i].name;
              }
              }
          
          
            newRange = '';   
            for (i=0; i<app.activeDocument.pages.length; i++)   
            {   
             if (app.activeDocument.pages[i].appliedMaster &&   
              mCheckbox[app.activeDocument.pages[i].appliedMaster.index].checkedState == true)   
             {   
              if (newRange) newRange += ',';   
              newRange += app.activeDocument.pages[i].name;   
             }   
            }   
            app.pdfExportPreferences.pageRange = newRange;   
            // alert (newRange);   
            app.activeDocument.exportFile (ExportFormat.PDF_TYPE, File((app.activeDocument.fullName.fsName +'_'+ myBaseName +'!').replace(/(\.indd)?!$/i, '.pdf')), true, app.pdfExportPresets[0]);   
          }
          
          

           

          This exports a file "export-test" as "export-test_B-Master+C-Master.pdf".

          • 2. Re: Name PDF as Masterpage Name
            beh_gras_beh Level 1

            That's it!

             

            I was creating an headache for myself here.

             

            Thanks a million Jongware!

             

             

            Small update that adds folder location and an option to rename the basefile thanks to Jongware:

             

            if(app.documents.length != 0){ 
            var myFolder = Folder.selectDialog ("Choose a Folder to Save the PDFs"); 
            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 myDialog = app.dialogs.add(); 
            with(myDialog.dialogColumns.add().dialogRows.add()){ 
            staticTexts.add({staticLabel:"Please Modify the Base Name if Necissary:"}); 
            var myBaseNameField = textEditboxes.add({editContents:myDocumentName, 
            minWidth:160}); 
            } 
            var myResult = myDialog.show({name:"ExportPages"}); 
            if(myResult == true){ 
            var myBaseName = myBaseNameField.editContents; 
            //Remove the dialog box from memory. 
            myDialog.destroy(); 
            
            
            
            
            
            
            var mCheckbox = [];  
            var expMasterDialog = app.dialogs.add({name:"Choose a Spread ", canCancel:true});  
            with (expMasterDialog)  
            {  
            with(dialogColumns.add())  
            {  
              for (i=0; i<app.activeDocument.masterSpreads.length; i++)  
              {  
               with(dialogRows.add())  
               {  
                mCheckbox[i] = checkboxControls.add({staticLabel:app.activeDocument.masterSpreads[i].name,checkedState:false});  
               }  
              }  
            }  
            }  
            
            
            
            
            
            
            if (expMasterDialog.show() == true)     
            {  
                var mySpreadName = '';  
                for (i=0; i<app.activeDocument.masterSpreads.length; i++)  
                {  
                if (mCheckbox[i].checkedState == true)  
                {  
                if (mySpreadName)  
                mySpreadName += '+';  
                mySpreadName += app.activeDocument.masterSpreads[i].name;  
                }  
                }  
              
              
              newRange = '';     
              for (i=0; i<app.activeDocument.pages.length; i++)     
              {     
               if (app.activeDocument.pages[i].appliedMaster &&     
                mCheckbox[app.activeDocument.pages[i].appliedMaster.index].checkedState == true)     
               {     
                if (newRange) newRange += ',';     
                newRange += app.activeDocument.pages[i].name;     
               }     
              }     
              app.pdfExportPreferences.pageRange = newRange;     
              // alert (newRange);   
            
            
            
            
            
            
            myFilePath = myFolder + "/" + myBaseName + mySpreadName + "_" + ".pdf"; 
            myFile = new File(myFilePath); 
            myDocument.exportFile(ExportFormat.pdfType, myFile, true, app.pdfExportPresets[0]);  
            
            
            }  
            }
            }