2 Replies Latest reply on Feb 12, 2018 9:51 AM by deelbe

    Need script to batch convert vector .eps to .svg images script

    pascalclijsters

      Hi,

       

      I'm looking for a script/program that if you run it, all the .eps files in a folder will batch convert to a .svg.

       

      I have already found a script to convert .eps to .png-24, but don't know how to edit it to export to .svg.

       

      Pascal

       

      .eps to .png-24 script

      /********************************************************** ADOBE SYSTEMS INCORPORATED  Copyright 2005 Adobe Systems Incorporated  All Rights Reserved  NOTICE:  Adobe permits you to use, modify, and  distribute this file in accordance with the terms of the Adobe license agreement accompanying it.   If you have received this file from a source  other than Adobe, then your use, modification, or distribution of it requires the prior  written permission of Adobe.  *********************************************************/    /********************************************************** Save as PDFs.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, pngExportOpts;    // Select the source folder.  sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );    // If a valid folder is selected  if ( sourceFolder != null )  {      files = new Array();      fileType = 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 PNG files.', '~' );          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 getPNGOptions get the PNGExportOptions for the files              pngExportOpts = getPNGOptions();                            // Export as PNG              sourceDoc.exportFile( targetFile, ExportType.PNG24, pngExportOpts );                            sourceDoc.close(SaveOptions.DONOTSAVECHANGES);          }          alert( 'Files are saved as PNG 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 = '.png'; // new extension for png file      newName = "";                for ( var i = 0 ; docName[i] != "." ; i++ )      {          newName += docName[i];      }      newName += ext; // full png name of the file            // Create a file object to save the png      saveInFile = new File( destFolder + '/' + newName );              return saveInFile;  }          /********************************************************* getPNGOptions: Function to set the PNG saving options of the  files using the PDFSaveOptions object. **********************************************************/    function getPNGOptions()  {            // Create the PDFSaveOptions object to set the PDF options      var pngExportOpts = new ExportOptionsPNG24();                        // Setting PNGExportOptions properties. Please see the JavaScript Reference      // for a description of these properties.      // Add more properties here if you like      pngExportOpts.antiAliasing = true;      pngExportOpts.artBoardClipping = true;      pngExportOpts.horizontalScale = 100.0;      //pngExportOpts.matte = true;      //pngExportOpts.matteColor = 0, 0, 0;      pngExportOpts.saveAsHTML = false;      pngExportOpts.transparency = true;      pngExportOpts.verticalScale = 100.0;        return pngExportOpts;  } 
        • 1. Re: Need script to batch convert vector .eps to .svg images script
          itsBenMason Level 2

          Not tested but should work, just changed the PNG options to SVG options and also changed extension to .svg

           

          /********************************************************** 
          
          ADOBE SYSTEMS INCORPORATED  
          Copyright 2005 Adobe Systems Incorporated  
          All Rights Reserved  
          
          NOTICE:  Adobe permits you to use, modify, and  
          distribute this file in accordance with the terms 
          of the Adobe license agreement accompanying it.   
          If you have received this file from a source  
          other than Adobe, then your use, modification, 
          or distribution of it requires the prior  
          written permission of Adobe.  
          
          *********************************************************/  
            
          /********************************************************** 
          
          Save as PDFs.js 
          
          DESCRIPTION 
          
          This sample gets files specified by the user from the  
          selected folder and batch processes them and saves them  
          as SVGs 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, pngExportOpts;  
            
          // Select the source folder.  
          sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );  
            
          // If a valid folder is selected  
          if ( sourceFolder != null )  
          {  
              files = new Array();  
              fileType = 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 PNG files.', '~' );  
                  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();  
                        
                      // Create SVG Options Object
                      var options = new ExportOptionsSVG();
                        
                      // Export as SVG  
                      sourceDoc.exportFile( targetFile, ExportType.SVG, options );  
                        
                      sourceDoc.close(SaveOptions.DONOTSAVECHANGES);  
                  }  
                  alert( 'Files are saved as SVG 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 = '.svg'; // new extension for sag file  
              newName = "";  
                    
              for ( var i = 0 ; docName[i] != "." ; i++ )  
              {  
                  newName += docName[i];  
              }  
              newName += ext; // full sag name of the file  
                
              // Create a file object to save the sag
              saveInFile = new File( destFolder + '/' + newName );  
                
            
              return saveInFile;  
          }  
          
          • 2. Re: Need script to batch convert vector .eps to .svg images script
            deelbe Level 1

            Thanks for posting! I tweaked the script to only export .eps to .svg. Also fixed the 'PNG' file type in the dialog and added a 'var' to the i = 0 in the first for loop. I tested the script and it works.

             

            
            /**********************************************************   
            
            
            DESCRIPTION  
            
            
            This sample gets files specified by the user from the   
            selected folder and batch processes them and saves them   
            as SVGs 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, pngExportOpts;    
            
            
            // Select the source folder.    
            sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to SVG', '~' );    
            
            
            // If a valid folder is selected    
            if ( sourceFolder != null )    
            {    
                files = new Array();    
                //fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );    
                fileType = '*.eps';
                
                // 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 PNG files.', '~' );    
                    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 svg    
                        targetFile = getNewName();    
            
            
                        // Create SVG Options Object  
                        var options = new ExportOptionsSVG();  
            
            
                        // Export as SVG    
                        sourceDoc.exportFile( targetFile, ExportType.SVG, options );    
            
            
                        sourceDoc.close(SaveOptions.DONOTSAVECHANGES);    
                    }    
                    alert( 'Files are saved as UNCOMPRESSED SVG 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 = '.svg'; // new extension for svg file    
                newName = "";    
            
            
                for ( var i = 0 ; docName[i] != "." ; i++ )    
                {    
                    newName += docName[i];    
                }    
                newName += ext; // full svg name of the file    
            
            
                // Create a file object to save the svg  
                saveInFile = new File( destFolder + '/' + newName );    
            
            
            
            
                return saveInFile;    
            }