Batch convert EPS/AI to PNG using Javascript

Copy link to clipboard
Copied
I have lots of eps and ai files which I would like to convert to PNG format. The reason for doing this is to make it easier to find the image that I want instead of opening it one by one. I know Photoshop can do the conversion but limited to JPG, PSD and TIFF only. The filesize also will be so huge and the image quality is not sharp.
One of the preset scripts for Adobe CS3 is SaveDocsAsPDF. I tried using this and then convert the PDF to PNG using Acrobat. I would required too much time to do it. I think there might be a better way to achieve the same result.
I am not a programmer and cant figure out how to tweak the SaveDocsAsPDF script and become SaveDocsAsPNG script.
It would be great if I can just select the folder and all the conversion will be done in the backgroud.
Anyone can help me?
Thanks
Explore related tutorials & articles
Copy link to clipboard
Copied

Copy link to clipboard
Copied
Hey Larry, can you please try reposting your solution? I have the same problem as immortaz but can't find your email or any other solutions out there..
Cheers
Copy link to clipboard
Copied
One of the scripts in my folder is from Adobe called ExportDocsAsPNG24.jsx It will ask you for an folder of AI and/or other file types openable by AI and will the process the files to PNG. You might look in the Scripting>Sample Files if it is not in Presets>Scriting.
Copy link to clipboard
Copied
Larry - ExportDocsAsPNG24.jsx doesn't seem to be present in AI CS6. Would you mind posting it or sending it to me?
Copy link to clipboard
Copied
/**********************************************************
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.
*********************************************************/
/**********************************************************
ExportDocsAsPNG24.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); // returns the document object
// Call function getNewName to get the name and file to save the png
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++ )
{
newName += docName;
}
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.
pngExportOpts.antiAliasing = true;
pngExportOpts.artBoardClipping = true;
//pngExportOpts.horizontalScale = 100.0;
//pngExportOpts.matte = true;
//pngExportOpts.matteColor = 0, 0, 0;
pngExportOpts.saveAsHTML = false;
pngExportOpts.transparency = false;
//pngExportOpts.verticalScale = 100.0;
return pngExportOpts;
}
Copy the above and paste into a text editor or the ESTK and save (from the text editor be sure to save as plain text). Place it into HD/Applications/Adobe Illustrator CS6/Presets/en_US/Scripts. Restart AI.
Copy link to clipboard
Copied
Thanks Larry, that hit the spot! Except how might I get it to export with 300dpi resolution, instead of the 72 it is defaulting to. I know how to do this on a manual export, but the ExportOptionsPNG24 doesn't seem to have an option for that.
Muppet Mark, the reason for this is that I have a BIG FOLDER full of .ai files, and the printing service I use requires .png format. I really don't feel like doing it manually 40 times!
Copy link to clipboard
Copied
To get them to 300ppi you will have to export at a scale of 416.667% and then resize (probably in Photoshop). Only way to do this.
Copy link to clipboard
Copied
I read the OP and thought you wanted the same thing ( to view the files without opening in AI ) sorry…
Copy link to clipboard
Copied
I can't understand why you would want to do this… Don't your AI files get previews…? Browse in Bridge… On a mac select a file click the spacebar…

Copy link to clipboard
Copied
Thanks for helping me out. I already send the email and still waiting for your reply.
Regards,
Copy link to clipboard
Copied

