Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Batch convert EPS/AI to PNG using Javascript

Guest
Mar 13, 2009 Mar 13, 2009
Hi,

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
TOPICS
Scripting
11.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Mar 13, 2009 Mar 13, 2009
Click on my name for my email and I'll send you what I have knocked up. I tried to post it but it wouldn't work.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Oct 13, 2010 Oct 13, 2010

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 13, 2010 Oct 13, 2010

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 21, 2013 Feb 21, 2013

Larry - ExportDocsAsPNG24.jsx doesn't seem to be present in AI CS6.  Would you mind posting it or sending it to me?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 21, 2013 Feb 21, 2013

/**********************************************************

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 22, 2013 Feb 22, 2013

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!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 22, 2013 Feb 22, 2013

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 22, 2013 Feb 22, 2013
LATEST

I read the OP and thought you wanted the same thing ( to view the files without opening in AI ) sorry…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Feb 21, 2013 Feb 21, 2013

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…

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Mar 24, 2009 Mar 24, 2009
Hi Larry,

Thanks for helping me out. I already send the email and still waiting for your reply.

Regards,
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Mar 24, 2009 Mar 24, 2009
Try out<br />http://hicksdesign.co.uk/journal/illustrator-exporting-layers-to-png<br /><br />var document = app.activeDocument;<br />if(document)<br />{ <br /> folder = document.fullName;<br /> var options = new ExportOptionsPNG24();<br /> options.antiAliasing = true;<br /> options.transparency = false;<br /> options.artBoardClipping = false;<br /> <br /> var n = document.layers.length;<br /> for(var i=0; i<n; ++i)<br /> {<br /> hideAllLayers();<br /> var layer = document.layers;<br /> layer.visible = true;<br /><br />// var file = new File(folder.fsName+"-"+layer.name+".png");<br />// Truncated for MAC<br /> var file = new File(document.path+"/"+layer.name+".png");<br /> <br /><br /> document.exportFile(file,ExportType.PNG24,options);<br /> <br /><br /> }<br /> <br /> showAllLayers();<br />}<br /><br />function hideAllLayers()<br />{<br /> forEach(document.layers, function(layer) {<br /> layer.visible = false;<br /> });<br />}<br /><br />function showAllLayers()<br />{<br /> forEach(document.layers, function(layer) {<br /> layer.visible = true;<br /> }); <br />}<br /><br />function forEach(collection, fn)<br />{<br /> var n = collection.length;<br /> for(var i=0; i<n; ++i)<br /> {<br /> fn(collection);<br /> }<br />}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines