2 Replies Latest reply on Sep 17, 2012 9:38 AM by Cleanshooter21

    Combine 2 different scripts

    acevans001

      i have a few different scripts that I use ALOT! I was wondering if any knew of a way to combine them.

       

      One make the ai file a pdf the smallest file size and the other makes the pdf hi-res for printing purposes and adds the word PRINT before the file extension

      I did not write these, however I did edit them for my purposes

       

      /**********************************************************

      Save as PDFs smalles file size without name.js

      DESCRIPTION

      This sample gets files specified by the user from the
      selected folder and batch processes them and saves them
      as PDFs in the user desired destination with the same
      file name.

      **********************************************************/

      // Main Code [Execution of script begins here]

      // uncomment to suppress Illustrator warning dialogs
      app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

      var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;

      // Select the source folder.
      sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PDF', '~' );

      // If a valid folder is selected
      if ( sourceFolder != null )
      {
      files = new Array();
      fileType = "*.ai"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' ); 

      // Get all files matching the pattern
      files = sourceFolder.getFiles( fileType );

      if ( files.length > 0 )
      {
      // Get the destination to save the files
      destFolder = sourceFolder;
      for ( i = 0; i < files.length; i++ )
      {
      sourceDoc = app.open(files[i]); // returns the document object

      // Call function getNewName to get the name and file to save the pdf
      targetFile = getNewName();

      // Call function getPDFOptions get the PDFSaveOptions for the files
      pdfSaveOpts = getPDFOptions( );

      // Save as pdf
      sourceDoc.saveAs( targetFile, pdfSaveOpts );

      sourceDoc.close();
      }
      alert( 'Files are saved as PDF in ' + destFolder );
      }
      else
      {
      alert( 'No matching files found' );
      }
      }

      /*********************************************************

      getNewName: Function to get the new file name. The primary
      name is the same as the source file.

      **********************************************************/

      function getNewName()
      {
      var ext, docName, newName, saveInFile, docName;
      docName = sourceDoc.name;
      ext = '.pdf'; // new extension for pdf file
      newName = "";

      for ( var i = 0 ; docName[i] != "." ; i++ )
      {
      newName += docName[i];
      }
      newName += ext; // full pdf name of the file

      // Create a file object to save the pdf
      saveInFile = new File( destFolder + '/' + newName );


      return saveInFile;
      }

      /*********************************************************

      getPDFOptions: Function to set the PDF saving options of the
      files using the PDFSaveOptions object.

      **********************************************************/

      function getPDFOptions()
      { var NamePreset = '[Smallest File Size]';

      // Create the PDFSaveOptions object to set the PDF options
      var pdfSaveOpts = new PDFSaveOptions();

      // Setting PDFSaveOptions properties. Please see the JavaScript Reference
      // for a description of these properties.
      // Add more properties here if you like
      pdfSaveOpts.acrobatLayers = true;
      pdfSaveOpts.colorBars = false;
      pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
      pdfSaveOpts.compressArt = true; //default
      pdfSaveOpts.embedICCProfile = false;
      pdfSaveOpts.enablePlainText = true;
      pdfSaveOpts.generateThumbnails = true; // default
      pdfSaveOpts.optimization = true;
      pdfSaveOpts.pageInformation = false;
      pdfSaveOpts.pDFPreset = NamePreset;

      // uncomment to view the pdfs after conversion.
      // pdfSaveOpts.viewAfterSaving = true;


      return pdfSaveOpts;
      }

       

       

      **********************************************************/

      // Main Code [Execution of script begins here]

      // uncomment to suppress Illustrator warning dialogs
      app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;

      var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;

      // Select the source folder.
      sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator .ai files you want to convert to PDF');

      // If a valid folder is selected
      if ( sourceFolder != null )
      {
          files = new Array();
          fileType = "*.ai"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );

          // Get all files matching the pattern
          files = sourceFolder.getFiles( fileType );

          if ( files.length > 0 )
          {
              // Get the destination to save the files
              //destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PDF files.', '~' );
              destFolder = sourceFolder;
              for ( i = 0; i < files.length; i++ )
              {
                  sourceDoc = app.open(files[i]); // returns the document object

                  // Call function getNewName to get the name and file to save the pdf
                  targetFile = getNewName();

                  // Call function getPDFOptions get the PDFSaveOptions for the files
                  pdfSaveOpts = getPDFOptions( );

                  // Save as pdf
                  sourceDoc.saveAs( targetFile, pdfSaveOpts );

                  sourceDoc.close();
              }
              alert( 'Files are saved as PDF in ' + destFolder );
          }
          else
          {
              alert( 'No matching files found' );
          }
      }

      /*********************************************************

      getNewName: Function to get the new file name. The primary
      name is the same as the source file.

      **********************************************************/

      function getNewName()
      {
          var ext, docName, newName, saveInFile, docName;
          docName = sourceDoc.name;
          ext = ' - PRINT.pdf'; // new extension for pdf file
          newName = "";

          for ( var i = 0 ; docName[i] != "." ; i++ )
          {
              newName += docName[i];
          }
          newName += ext; // full pdf name of the file

          // Create a file object to save the pdf
          saveInFile = new File( destFolder + '/' + newName );

          return saveInFile;
      }

      /*********************************************************

      getPDFOptions: Function to set the PDF saving options of the
      files using the PDFSaveOptions object.

      **********************************************************/

      function getPDFOptions()
      { var NamePreset = 'Print with Bleeds';

      // Create the PDFSaveOptions object to set the PDF options
      var pdfSaveOpts = new PDFSaveOptions();

      // Setting PDFSaveOptions properties. Please see the JavaScript Reference
      // for a description of these properties.
      // Add more properties here if you like
      pdfSaveOpts.acrobatLayers = true;
      pdfSaveOpts.colorBars = false;
      pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
      pdfSaveOpts.compressArt = true; //default
      pdfSaveOpts.embedICCProfile = false;
      pdfSaveOpts.enablePlainText = true;
      pdfSaveOpts.generateThumbnails = true; // default
      pdfSaveOpts.optimization = true;
      pdfSaveOpts.pageInformation = true;
      pdfSaveOpts.pDFPreset = NamePreset;

      // uncomment to view the pdfs after conversion.
      // pdfSaveOpts.viewAfterSaving = true;


      return pdfSaveOpts;
      }

        • 1. Re: Combine 2 different scripts
          Muppet Mark Level 5

          At the moment Im not sure… Would have to test… At present having 2 scripts open original *.ai files and do a save as then close… Combining would mean the active document would be the *.pdf after the first save as… It may be possible to undo that stage or you may want to make the better quality PDF first… Not sure all that syntax is required either…

          • 2. Re: Combine 2 different scripts
            Cleanshooter21

            This might do the trick...

             

            **********************************************************
            
            Save as PDFs smalles file size without name.js
            
            DESCRIPTION
            
            This sample gets files specified by the user from the
            selected folder and batch processes them and saves them
            as PDFs in the user desired destination with the same
            file name.
            
            **********************************************************/
            
            // Main Code [Execution of script begins here]
            
            // uncomment to suppress Illustrator warning dialogs
            //app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
            
            var destFolder, sourceFolder, files, fileType, pdfs, sourceDoc, targetFileSmall, targetFileLarge, pdfSaveOptsSmall, pdfSaveOptsBig;
            
            // Select the source folder.
            sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PDF', '~' );
            
            // If a valid folder is selected
            if ( sourceFolder != null ){
                files = new Array();
                fileType = "*.ai"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' ); 
            
                // Get all files matching the pattern
                files = sourceFolder.getFiles( fileType );
            
                if ( files.length > 0 ){
                    // Get the destination to save the files
                    destFolder = sourceFolder;
                    for (var i = 0; i < files.length; i++ ){
                        sourceDoc = app.open(files[i]); // returns the document object
            
                        // Call function getNewName to get the name and file to save the pdf
                        targetFileLarge = getNewName(true);
            
                        // Call function getPDFOptions get the PDFSaveOptions for the files
                        pdfSaveOptsLarge = getPDFOptions(true);
            
                        // Save as pdf
                        sourceDoc.saveAs( targetFileLarge, pdfSaveOptsLarge );
                        sourceDoc.close();
                    }
                }else{
                    alert( 'No matching files found' );
                }
            
                pdfs = new Array();
                fileType = "*.pdf"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' ); 
                
                pdfs = sourceFolder.getFiles (fileType);
                
                if ( pdfs.length > 0 ){
                    // Get the destination to save the files
                    destFolder = sourceFolder;
                    for (var i = 0; i < files.length; i++ ){
                        sourceDoc = app.open(pdfs[i]); // returns the document object
            
                        // Call function getNewName to get the name and file to save the pdf
                        targetFileSmall = getNewName(false);
            
                        // Call function getPDFOptions get the PDFSaveOptions for the files
                        pdfSaveOptsSmall = getPDFOptions(false);
            
                        // Save as pdf
                        sourceDoc.saveAs( targetFileSmall, pdfSaveOptsSmall );
                        sourceDoc.close();
                    }
                    alert( 'Files are saved as PDF in ' + destFolder );
                }else{
                    alert( 'No matching files found' );
                }
            }
            
            /*********************************************************
            
            getNewName: Function to get the new file name. The primary
            name is the same as the source file.
            
            **********************************************************/
            
            function getNewName(print){
                var ext, docName, newName, saveInFile, docName;
                docName = sourceDoc.name;
                if(print){
                    ext = ' - PRINT.pdf'; // new extension for pdf file
                }else{
                    ext = '.pdf'; // new extension for pdf file
                }
                newName = "";
            
                for ( var i = 0 ; docName[i] != "." ; i++ ){
                    newName += docName[i];
                }
                newName += ext; // full pdf name of the file
            
                // Create a file object to save the pdf
                saveInFile = new File( destFolder + '/' + newName );
            
            
                return saveInFile;
            }
            
            /*********************************************************
            
            getPDFOptions: Function to set the PDF saving options of the
            files using the PDFSaveOptions object.
            
            **********************************************************/
            
            function getPDFOptions(large){
                if(large){
                    var NamePreset = 'Print with Bleeds';
                }else{
                    var NamePreset = '[Smallest File Size]';
                }
            
                // Create the PDFSaveOptions object to set the PDF options
                var pdfSaveOpts = new PDFSaveOptions();
            
                // Setting PDFSaveOptions properties. Please see the JavaScript Reference
                // for a description of these properties.
                // Add more properties here if you like
                pdfSaveOpts.acrobatLayers = true;
                pdfSaveOpts.colorBars = false;
                pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
                pdfSaveOpts.compressArt = true; //default
                pdfSaveOpts.embedICCProfile = false;
                pdfSaveOpts.enablePlainText = true;
                pdfSaveOpts.generateThumbnails = true; // default
                pdfSaveOpts.optimization = true;
                pdfSaveOpts.pageInformation = false;
                pdfSaveOpts.viewAfterSaving = false;
                pdfSaveOpts.pDFPreset = NamePreset;
            
                // uncomment to view the pdfs after conversion.
                // pdfSaveOpts.viewAfterSaving = true;
            
            
                return pdfSaveOpts;
            }