Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 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');
- f = find_files(sourceFolder);
- function find_files (dir)
- {
- return find_files_sub (dir, []);
- }
- function find_files_sub (dir, array)
- {
- var f = Folder (dir).getFiles ("*.*");
- for (var i = 0; i < f.length; i++)
- {
- if (f[i] instanceof Folder)
- find_files_sub (f[i], array);
- else
- if (f[i].name.slice (-3).toLowerCase() == ".ai")
- array.push (f[i]);
- }
- // If a valid folder is selected
- if ( sourceFolder != null )
- {
- f = new Array();
- fileType = "*.ai"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );
- // Get all files matching the pattern
- f = sourceFolder.getFiles( fileType );
- if ( f.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 < f.length; i++ )
- {
- sourceDoc = app.open(f[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' );
- }
- }
- return array;
- }
- /*********************************************************
- 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()
- {
- // 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 = true;
- pdfSaveOpts.enablePlainText = true;
- pdfSaveOpts.generateThumbnails = true; // default
- pdfSaveOpts.optimization = true;
- pdfSaveOpts.pageInformation = false;
- pdfSaveOpts.preserveEditability = true;
- return pdfSaveOpts;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement