lucifer63

convertImages.jsx [Adobe Illustrator]

Aug 29th, 2017
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**********************************************************
  2.  
  3. ADOBE SYSTEMS INCORPORATED  
  4. Copyright 2005 Adobe Systems Incorporated  
  5. All Rights Reserved  
  6.  
  7. NOTICE:  Adobe permits you to use, modify, and  
  8. distribute this file in accordance with the terms
  9. of the Adobe license agreement accompanying it.  
  10. If you have received this file from a source  
  11. other than Adobe, then your use, modification,
  12. or distribution of it requires the prior  
  13. written permission of Adobe.  
  14.  
  15. *********************************************************/  
  16.  
  17. /**********************************************************
  18.  
  19. Save as PDFs.js
  20.  
  21. DESCRIPTION
  22.  
  23. This sample gets files specified by the user from the  
  24. selected folder and batch processes them and saves them  
  25. as PDFs in the user desired destination with the same  
  26. file name.
  27.  
  28. **********************************************************/  
  29.  
  30. // Main Code [Execution of script begins here]  
  31.  
  32. // uncomment to suppress Illustrator warning dialogs  
  33. // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;  
  34.  
  35. var destFolder, sourceFolder, files, fileType, sourceDoc, targetFile, pngExportOpts;  
  36.  
  37. // Select the source folder.  
  38. sourceFolder = Folder.selectDialog( 'Select the folder with Illustrator files you want to convert to PNG', '~' );  
  39.  
  40. // If a valid folder is selected  
  41. if ( sourceFolder != null )  
  42. {  
  43.     files = new Array();  
  44.     fileType = prompt( 'Select type of Illustrator files to you want to process. Eg: *.eps', '*.eps' );  
  45.      
  46.     // Get all files matching the pattern  
  47.     files = sourceFolder.getFiles( fileType );  
  48.      
  49.     if ( files.length > 0 )  
  50.     {  
  51.         // Get the destination to save the files  
  52.         destFolder = Folder.selectDialog( 'Select the folder where you want to save the converted PNG files.', '~' );  
  53.         for ( i = 0; i < files.length; i++ )  
  54.         {  
  55.             sourceDoc = app.open(files[i]); // returns the document object  
  56.                                      
  57.             // Call function getNewName to get the name and file to save the pdf  
  58.             targetFile = getNewName();  
  59.              
  60.             // Call function getPNGOptions get the PNGExportOptions for the files  
  61.             pngExportOpts = getPNGOptions();  
  62.              
  63.             // Export as PNG  
  64.             sourceDoc.exportFile( targetFile, ExportType.PNG24, pngExportOpts );  
  65.              
  66.             sourceDoc.close(SaveOptions.DONOTSAVECHANGES);  
  67.         }  
  68.         alert( 'Files are saved as PNG in ' + destFolder );  
  69.     }  
  70.     else  
  71.     {  
  72.         alert( 'No matching files found' );  
  73.     }  
  74. }  
  75.  
  76.  
  77.  
  78.  
  79. /*********************************************************
  80.  
  81. getNewName: Function to get the new file name. The primary
  82. name is the same as the source file.
  83.  
  84. **********************************************************/  
  85.  
  86. function getNewName()  
  87. {  
  88.     var ext, docName, newName, saveInFile, docName;  
  89.     docName = sourceDoc.name;  
  90.     ext = '.png'; // new extension for png file  
  91.     newName = "";  
  92.          
  93.     for ( var i = 0 ; docName[i] != "." ; i++ )  
  94.     {  
  95.         newName += docName[i];  
  96.     }  
  97.     newName += ext; // full png name of the file  
  98.      
  99.     // Create a file object to save the png  
  100.     saveInFile = new File( destFolder + '/' + newName );  
  101.      
  102.  
  103.     return saveInFile;  
  104. }  
  105.  
  106.  
  107.  
  108.  
  109. /*********************************************************
  110.  
  111. getPNGOptions: Function to set the PNG saving options of the  
  112. files using the PDFSaveOptions object.
  113.  
  114. **********************************************************/  
  115.  
  116. function getPNGOptions()  
  117. {  
  118.      
  119.     // Create the PDFSaveOptions object to set the PDF options  
  120.     var pngExportOpts = new ExportOptionsPNG24();  
  121.      
  122.      
  123.      
  124.     // Setting PNGExportOptions properties. Please see the JavaScript Reference  
  125.     // for a description of these properties.  
  126.     // Add more properties here if you like  
  127.     pngExportOpts.antiAliasing = true;
  128.     pngExportOpts.artBoardClipping = false;
  129.     //pngExportOpts.matte = true;  
  130.     //pngExportOpts.matteColor = 0, 0, 0;  
  131.     pngExportOpts.saveAsHTML = false;  
  132.     pngExportOpts.transparency = true;
  133.     // *scale actually is not a scale, this attribute controls PPI of exported file
  134.     // Use 416.667 value to achieve maximum available PPI of 300
  135.     pngExportOpts.verticalScale = 416.667;
  136.     pngExportOpts.horizontalScale = 416.667;
  137.  
  138.     return pngExportOpts;  
  139. }
Advertisement
Add Comment
Please, Sign In to add comment