2 Replies Latest reply on Nov 9, 2015 2:48 PM by bigfish2224

    Automate Exporting PDF to a specific folder without dialog box

    bigfish2224 Level 1

      Hi, this post is a continuation from another post post, but this forum is more relevant.

       

      Basically, I asked if I could automate the export of my InDesign file to two different PDF settings (one for Print, one for Web)

      I got it working, but one step I can't seem to avoid is having to deal with a dialog box that asks me where to save the file.

       

      In an ideal world, I would LOVE to simply finish working on my InDesign file, run a script that would automate the export to multiple PDF's using my custom Print and Web settings, and automatically put those PDF's in a folder (that I set in the script itself - not in a dialog box)

       

      Here's the script I modifed:

       

      // BS"D 
      // All rights reserved (c) 2015 by Id-Extras.com 
      // Free to use and modify but do not delete this copyright attribution. 
      // This script will export 2 pdfs of the current document 
      // Choose the PDF presets by altering their names below 
      // The second PDF gets a suffix added to its name. 
      // Modify the line below beginning name2 = to change the suffix. 
      // For more InDesign scripts: www.Id-Extras.com 
      d = app.activeDocument; 
      // Here you can choose the PDF preset 
      preset1 = app.pdfExportPresets.itemByName("Hubcast Ready-Press Quality"); 
      preset2 = app.pdfExportPresets.itemByName("Web-Ready (JPEG High 200dpi - No Color Conversion)"); 
      if (!(preset1.isValid && preset2.isValid)){ 
       alert("One of the presets does not exist. Please check spelling carefully."); 
       exit(); 
      } 
      if (d.saved){ 
       thePath = String(d.fullName).replace(/\..+$/, "") + ".pdf"; 
       thePath = String(new File(thePath).saveDlg()); 
      } 
      else{ 
       thePath = String((new File).saveDlg()); 
      } 
      thePath = thePath.replace(/\.pdf$/, ""); 
      name1 = thePath+"_PRINT.pdf"; 
      // Here you can set the suffix at the end of the name 
      name2 = thePath+"_WEB.pdf"; 
      d.exportFile(ExportFormat.PDF_TYPE, new File(name1), false, preset1); 
      d.exportFile(ExportFormat.PDF_TYPE, new File(name2), false, preset2);
      

       

       

      My document structure is as follows below, so I basically want to modify the script so that the final PDF's ("_PRINT" and "_WEB")  automatically export to the "Finals" folder, which I always place one level up from the folder containing the InDesign File.

      Screen Shot 2015-11-09 at 10.17.54 AM.png

      Thanks in advance!

        • 1. Re: Automate Exporting PDF to a specific folder without dialog box
          Ronald63 Level 4

          Hi,

           

          I hope this code can answer your request ;-)

           

          d = app.activeDocument;   
          preset1 = app.pdfExportPresets.itemByName("Hubcast Ready-Press Quality");   
          preset2 = app.pdfExportPresets.itemByName("Web-Ready (JPEG High 200dpi - No Color Conversion)");       
          if (!(preset1.isValid && preset2.isValid)){   
              alert("One of the presets does not exist. Please check spelling carefully.");   
              exit();   
          } 
          
          mDocName = d.name.substr (0, d.name.lastIndexOf('.'));
          mSourcePath = d.fullName.parent.toString();
          mRootPath =mSourcePath.substr (0, mSourcePath.lastIndexOf('/'));
          mTargetPath=mRootPath.concat('/final/');
          
          mNamePrint = mTargetPath.concat(mDocName,'_PRINT.pdf');   
          mNameWeb= mTargetPath.concat(mDocName,'_WEB.pdf');
          
          if (!d.saved){   
              d.save;
          }    
          
          d.exportFile(ExportFormat.PDF_TYPE, new File(mNamePrint), false, preset1);   
          d.exportFile(ExportFormat.PDF_TYPE, new File(mNameWeb), false, preset2);  
          
          • 2. Re: Automate Exporting PDF to a specific folder without dialog box
            bigfish2224 Level 1

            Thank you so much! It works! I just changed the name of the the final to "finals" and have to make sure that a folder is already there before running the script.

            I suppose I could add a third preset if I wanted another PDF setting to be used, but this is perfect as is.

            This is awesome. Really appreciate it!