Skip to content

Instantly share code, notes, and snippets.

@morisono
Forked from scootcho/EpsBulkConvertSVG.js
Created February 10, 2025 11:42
Show Gist options
  • Save morisono/4614b416e2d2722808bdaeaa1498f5e8 to your computer and use it in GitHub Desktop.
Save morisono/4614b416e2d2722808bdaeaa1498f5e8 to your computer and use it in GitHub Desktop.
adobe illustrator EPS to SVG bulk conversion
/**********************************************************
DESCRIPTION
This sample gets files specified by the user from the
selected folder and batch processes them and saves them
as SVGs 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 SVG",
"~"
);
// 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', ' ' );
fileType = "*.eps";
// 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 (var i = 0; i < files.length; i++) {
sourceDoc = app.open(files[i]); // returns the document object
// Call function getNewName to get the name and file to save the svg
// targetFile = getNewName();
// Create SVG Options Object
var exportOptionsSVG = new ExportOptionsSVG();
// // SVG export options
exportOptionsSVG.embedRasterImages = true;
// exportOptionsSVG.embedAllFonts = false;
// exportOptionsSVG.coordinatePrecision = 3;
// exportOptionsSVG.fontSubsetting = SVGFontSubsetting.GLYPHSUSED;
var type = ExportType.SVG;
targetFile = getTargetFile(sourceDoc.name, ".svg", destFolder);
sourceDoc.exportFile(targetFile, type, exportOptionsSVG);
sourceDoc.close(SaveOptions.DONOTSAVECHANGES);
}
alert("Files are saved as UNCOMPRESSED SVG in " + destFolder);
} else {
alert("No matching files found");
}
}
function getTargetFile(docName, ext, destFolder) {
var newName = "";
// if name has no dot (and hence no extension),
// just append the extension
if (docName.indexOf(".") < 0) {
newName = docName + ext;
} else {
var dot = docName.lastIndexOf(".");
newName += docName.substring(0, dot);
newName += ext;
}
// Create the file object to save to
var myFile = new File(destFolder + "/" + newName);
// Preflight access rights
if (myFile.open("w")) {
myFile.close();
} else {
throw new Error("Access is denied");
}
return myFile;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment