Advertisement
Guest User

Subfolders - Test

a guest
Nov 26th, 2012
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Main Code [Execution of script begins here]
  3.  
  4. // uncomment to suppress Illustrator warning dialogs
  5. // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
  6.  
  7. var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;
  8.  
  9. // Select the source folder.
  10. sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator .ai files you want to convert to PDF');
  11. f = find_files(sourceFolder);
  12.  
  13. function find_files (dir)
  14.     {
  15.     return find_files_sub (dir, []);
  16.     }
  17.  
  18. function find_files_sub (dir, array)
  19.     {
  20.     var f = Folder (dir).getFiles ("*.*");
  21.     for (var i = 0; i < f.length; i++)
  22.         {
  23.         if (f[i] instanceof Folder)
  24.             find_files_sub (f[i], array);
  25.         else
  26.             if (f[i].name.slice (-3).toLowerCase() == ".ai")
  27.                 array.push (f[i]);
  28.         }
  29.  
  30.             // If a valid folder is selected
  31.         if ( sourceFolder != null )
  32.         {
  33.             f = new Array();
  34.             fileType = "*.ai"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );
  35.  
  36.             // Get all files matching the pattern
  37.             f = sourceFolder.getFiles( fileType );
  38.  
  39.             if ( f.length > 0 )
  40.             {
  41.                 // Get the destination to save the files
  42.                 //destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PDF files.', '~' );
  43.                 destFolder = sourceFolder;
  44.                 for ( i = 0; i < f.length; i++ )
  45.                 {
  46.                     sourceDoc = app.open(f[i]); // returns the document object
  47.  
  48.                     // Call function getNewName to get the name and file to save the pdf
  49.                     targetFile = getNewName();
  50.  
  51.                     // Call function getPDFOptions get the PDFSaveOptions for the files
  52.                     pdfSaveOpts = getPDFOptions( );
  53.  
  54.                     // Save as pdf
  55.                     sourceDoc.saveAs( targetFile, pdfSaveOpts );
  56.  
  57.                     sourceDoc.close();
  58.                 }
  59.                 alert( 'Files are saved as PDF in ' + destFolder );
  60.             }
  61.             else
  62.             {
  63.                 alert( 'No matching files found' );
  64.             }
  65.         }
  66.    
  67.     return array;
  68.     }
  69.  
  70.  
  71.  
  72. /*********************************************************
  73.  
  74. getNewName: Function to get the new file name. The primary
  75. name is the same as the source file.
  76.  
  77. **********************************************************/
  78.  
  79. function getNewName()
  80. {
  81.     var ext, docName, newName, saveInFile, docName;
  82.     docName = sourceDoc.name;
  83.     ext = '.pdf'; // new extension for pdf file
  84.     newName = "";
  85.  
  86.     for ( var i = 0 ; docName[i] != "." ; i++ )
  87.     {
  88.         newName += docName[i];
  89.     }
  90.     newName += ext; // full pdf name of the file
  91.  
  92.     // Create a file object to save the pdf
  93.     saveInFile = new File( destFolder + '/' + newName );
  94.  
  95.     return saveInFile;
  96. }
  97.  
  98. /*********************************************************
  99.  
  100. getPDFOptions: Function to set the PDF saving options of the
  101. files using the PDFSaveOptions object.
  102.  
  103. **********************************************************/
  104.  
  105. function getPDFOptions()
  106. {
  107.     // Create the PDFSaveOptions object to set the PDF options
  108.     var pdfSaveOpts = new PDFSaveOptions();
  109.  
  110.     // Setting PDFSaveOptions properties. Please see the JavaScript Reference
  111.     // for a description of these properties.
  112.     // Add more properties here if you like
  113.     pdfSaveOpts.acrobatLayers = true;
  114.     pdfSaveOpts.colorBars = false;
  115.     pdfSaveOpts.colorCompression = CompressionQuality.AUTOMATICJPEGHIGH;
  116.     pdfSaveOpts.compressArt = true; //default
  117.     pdfSaveOpts.embedICCProfile = true;
  118.     pdfSaveOpts.enablePlainText = true;
  119.     pdfSaveOpts.generateThumbnails = true; // default
  120.     pdfSaveOpts.optimization = true;
  121.     pdfSaveOpts.pageInformation = false;
  122.     pdfSaveOpts.preserveEditability = true;
  123.  
  124.     return pdfSaveOpts;
  125. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement