Copy link to clipboard
Copied
I want to export all *.ai files as *.jpg files.
I tried the code below.
main();
function main() {
var document = app.activeDocument;
var outputFolder = new File('/Users/sondaehyeon/Desktop/A')
var opts = new ExportOptionsJPEG();
opts.antiAliasing = true;
opts.horizontalScale = 100;
opts.verticalScale = 100;
opts.qualitySetting = 100;
document.exportFile(outputFolder, ExportType.JPEG, opts)
}
However, the above code has been saved as an RGB JPG file.
But, I need CYMK color.
And I want to go to all the subfolders and work on them.
Hi,
ColorModel property is missing for scrripting. You can read below articles
Answer to your question
function exportJPG(pth){ //Export 300dpi CMYK jpg
var str = "";
for (var i=0;i<pth.length;i++) str += u16to8(pth.charCodeAt(i));
var act
...
Copy link to clipboard
Copied
I'm not sure, but does what happens if you change the document colorspace before exporting?
app.activeDocument.documentColorSpace = DocumentColorSpace.CMYK;
Copy link to clipboard
Copied
Hi,
ColorModel property is missing for scrripting. You can read below articles
Answer to your question
function exportJPG(pth){ //Export 300dpi CMYK jpg
var str = "";
for (var i=0;i<pth.length;i++) str += u16to8(pth.charCodeAt(i));
var act = "/version 3/name [ 4 73657431]/isOpen 1"
+ "/actionCount 1/action-1 {/name [ 4 61637431]/keyIndex 0/colorIndex 0/isOpen 1/eventCount 1"
+ "/event-1 {/useRulersIn1stQuadrant 0/internalName (adobe_exportDocument)"
+ "/isOpen 0/isOn 1/hasDialog 1/showDialog 0/parameterCount 7"
+ "/parameter-1 {/key 1885434477/showInPalette 0/type (raw)"
+ "/value < 100 0a00000001000000030000000100000000002c01020000000000000001000000"
+ "69006d006100670065006d006100700000000000000000000000000000000000"
+ "0000000000000000000000000000000000000000000000000000000000000000"
+ "00000100>/size 100}" //Probably, parameter for exporter plugin
+ "/parameter-2 {/key 1851878757/showInPalette 4294967295"
+ "/type (ustring)/value [ " + str.length/2 + " " + str + "]}"
+ "/parameter-3 {/key 1718775156/showInPalette 4294967295"
+ "/type (ustring)/value [ 16 4a5045472066696c6520666f726d6174]}" // JPEG file format
+ "/parameter-4 {/key 1702392942/showInPalette 4294967295"
+ "/type (ustring)/value [ 12 6a70672c6a70652c6a706567]}" //jpg,jpe,jpeg
+ "/parameter-5 {/key 1936548194/showInPalette 4294967295/type (boolean)/value 0}"
+ "/parameter-6 {/key 1935764588/showInPalette 4294967295/type (boolean)/value 1}"
+ "/parameter-7 {/key 1936875886/showInPalette 4294967295/type (ustring)/value [ 0]}}}"
var tmp = File(Folder.desktop + "/set1.aia");
tmp.open('w');
tmp.write(act);
tmp.close();
app.loadAction(tmp);
app.doScript("act1", "set1", false);
app.unloadAction("set1","");
tmp.remove();
}
function u16to8(cd) {
var out =
(cd < 0x80
? toHex2(cd)
: (cd < 0x800
? toHex2(cd >> 6 & 0x1f | 0xc0)
: toHex2(cd >> 12 | 0xe0) +
toHex2(cd >> 6 & 0x3f | 0x80)
) + toHex2(cd & 0x3f | 0x80)
);
return out;
}
function toHex2(num) {
var out = '0' + num.toString(16);
return out.slice(-2);
}
var pth = '/Users/sondaehyeon/Desktop/A';
for(var i=0;i<app.documents.length;i++){
app.activeDocument = app.documents[i];
exportJPG(pth);
}
Above code will export all ai files that are open in the Illustrator into JPEG with CMYK color model.
Credit @Ten A
Let us know if this works for you.
Copy link to clipboard
Copied
Wow! Horrible to have to work around, but amazing! 🙂
Copy link to clipboard
Copied
Using CMYK jpgs in the real world can be problematic. Most image software expects jpgs to be in RGB and will not display the image correctly.