Last active
December 8, 2023 01:44
-
-
Save sempostma/4ee699a78a5cd0ccac150f95d78b0e9d to your computer and use it in GitHub Desktop.
Export Illustrator document to a buch of different file formats and resolutions. File formats include: .ai, .pdf, .png, .jpg and .svg. Installation: Copy this file to your illustrator scripts folder (For windows: C:\Program Files\Adobe\Adobe Illustrator CC 2019\Presets\<your locale>\Scripts) (For Mac: Applications/Adobe Illustrator CC/Presets/<y…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author: Sem Postma (sem@esstudio.site) | |
* Name: Final Export | |
* License: MIT | |
* | |
* Installation: Copy this file to your illustrator scripts folder: | |
* For windows: C:\Program Files\Adobe\Adobe Illustrator CC 2019\Presets\<your locale>\Scripts | |
* For Mac: Applications/Adobe Illustrator CC/Presets/<your locale>/Scripts | |
* | |
* Usage: File->Scripts->Final Export | |
* Questions? Send me an email. | |
* Download link: https://gist.github.com/sempostma/4ee699a78a5cd0ccac150f95d78b0e9d/archive/3b6a5a282315706b5c08c5f626cddc174dfe1c47.zip | |
* | |
* Output file structure: | |
* /<choosen output folder> | |
* /pictogram | |
* /<choosen filename>.jpg | |
* /<choosen filename>.png | |
* /icon | |
* /<choosen filename>.jpg | |
* /<choosen filename>.png | |
* /small | |
* /<choosen filename>.jpg | |
* /<choosen filename>.png | |
* /large | |
* /<choosen filename>.jpg | |
* /<choosen filename>.png | |
* /xlarge | |
* /<choosen filename>.jpg | |
* /<choosen filename>.png | |
* /<choosen filename>.ai | |
* /<choosen filename>.pdf | |
* /<choosen filename>.svg | |
* /<choosen filename>.jpg | |
* /<choosen filename>.png | |
* | |
* TIP: You can keep exporting different variations to the same output folder as long as you choose a different name when exporting. Be carefull, files can be overidden. | |
*/ | |
var folder = Folder.selectDialog(); | |
var document = app.activeDocument; | |
var myFilename = prompt('The name of your files.', '', 'Filename'); | |
var rootDest = folder.fsName + "/" + myFilename; | |
if (document && folder) { | |
exportSVG(rootDest); | |
savePNG(rootDest); | |
exportDXF(rootDest); | |
exportEPS(rootDest); | |
exportFileToJPEG(rootDest); | |
var illustratorSaveOptions = new IllustratorSaveOptions(); | |
document.saveAs( new File(rootDest + '.ai'), illustratorSaveOptions ); | |
saveFileToPDF(rootDest); | |
saveToRes(10, "pictogram"); | |
saveToRes(20, "icon"); | |
saveToRes(50, "small"); | |
saveToRes(200, "large"); | |
saveToRes(500, "xlarge"); | |
alert('Done!') | |
} | |
function saveToRes(scaleTo, resFolderName) { | |
if (!scaleTo) scaleTo = 300; | |
var resFolder; | |
resFolder = new Folder(folder.fsName + "/" + resFolderName); | |
if (!resFolder.exists) { | |
resFolder.create(); | |
} | |
var dest = resFolder.fsName + "/" + myFilename; | |
exportFileToJPEG(dest, scaleTo); | |
savePNG(dest, scaleTo); | |
} | |
function hideAllLayers() { | |
var i, layer; | |
for (i = document.layers.length - 1; i >= 0; i--) { | |
layer = document.layers[i]; | |
if (!layer.locked && layer.name.indexOf("!") === -1) { | |
layer.visible = false; | |
} | |
} | |
} | |
function saveFileToPDF(dest) { | |
var doc = app.activeDocument; | |
if (app.documents.length > 0) { | |
var saveName = new File(dest + '.pdf'); | |
saveOpts = new PDFSaveOptions(); | |
saveOpts.colorCompression = CompressionQuality.ZIP8BIT | |
saveOpts.colorDownsamplingMethod = DownsampleMethod.AVERAGEDOWNSAMPLE | |
saveOpts.compatibility = PDFCompatibility.ACROBAT5; | |
saveOpts.generateThumbnails = true; | |
saveOpts.preserveEditability = true; | |
doc.saveAs(saveName, saveOpts); | |
} | |
} | |
function exportFileToJPEG(dest, scaleTo) { | |
var exportOptions = new ExportOptionsJPEG(); | |
var type = ExportType.JPEG; | |
exportOptions.artBoardClipping = true; | |
exportOptions.antiAliasing = true; | |
exportOptions.qualitySetting = 100; | |
if (scaleTo) { | |
exportOptions.verticalScale = scaleTo; | |
exportOptions.horizontalScale = scaleTo; | |
} | |
document.exportFile(new File(dest + ".jpg"), type, exportOptions); | |
} | |
function exportEPS(dest) { | |
var saveOpts = new EPSSaveOptions(); | |
saveOpts.cmykPostScript = true; | |
saveOpts.compatibility = Compatibility.ILLUSTRATOR16; | |
saveOpts.embedAllFonts = false; | |
saveOpts.embedLinkedFiles = false; | |
saveOpts.includeDocumentThumbnails = false; | |
saveOpts.postScript = EPSPostScriptLevelEnum.LEVEL3; | |
saveOpts.preview = EPSPreview.None; | |
saveOpts.saveMultipleArtboards = false; | |
document.saveAs(new File(dest + '.eps'), saveOpts ); | |
} | |
function exportDXF(dest) { | |
var exportOptions = new ExportOptionsAutoCAD(); | |
exportOptions.exportFileFormat = AutoCADExportFileFormat.DXF;//DWG DXF | |
exportOptions.exportOption = AutoCADExportOption.PreserveAppearance; | |
exportOptions.version = AutoCADCompatibility.AutoCADRelease14; | |
exportOptions.exportSelectedArtOnly = true; //export selected objects true | |
exportOptions.convertTextToOutlines = false; | |
exportOptions.generateThumbnails = true | |
exportOptions.unit = AutoCADUnit.Millimeters; | |
var file = new File(dest + '.dxf'); | |
document.exportFile(file, ExportType.AUTOCAD, exportOptions); | |
} | |
function exportSVG(dest) { | |
var targetFile = new File(dest + ".svg"); | |
svgSaveOpts = new ExportOptionsSVG(); | |
svgSaveOpts.fontType = SVGFontType.OUTLINEFONT; | |
document.exportFile(targetFile, ExportType.SVG, svgSaveOpts); | |
} | |
function savePNG(dest, scaleTo) { | |
var targetFile = new File(dest + ".png"); | |
var options = new ExportOptionsPNG24(); | |
options = new ExportOptionsPNG24(); | |
options.antiAliasing = true; | |
options.transparency = true; | |
options.artBoardClipping = true; | |
if (scaleTo) { | |
options.verticalScale = scaleTo; | |
options.horizontalScale = scaleTo; | |
} | |
document.exportFile(targetFile, ExportType.PNG24, options); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment