batch able to ungroup PDF objects and change colors from RGB into CMYK with lookuptable
Hi !
I am a beginner with AI but I know it's very powerful !
I have several RGB PDF files with grouped objects and I want to develop a script that :
- is able to process several PDF files (e.g. all PDF in a folder)
- ungroup the objects of each PDF file (I found the UngroupV1.js script on this forum, I want to combine it into my final script for batch process)
- convert RGB PDF to CMYK PDF using a txt lookup table where I can set myself the values (I don't use a lot of colors but I have to get precise CMYK values)
I found this script (here) that "select all items in your original document, create a new CMYK document and paste it" :
- #target illustrator
- doc=activeDocument;
- for (i=0; i<doc.layers.length; i++){doc.layers.hasSelectedArtwork=true;} // select all
- copy();//
- doc2=documents.add(DocumentColorSpace.CMYK,doc.width,doc.height,doc.artboards.length); // new doc CMYK
- doc2.rulerOrigin=doc.rulerOrigin; //
- doc2.pageOrigin=doc.pageOrigin; //
- paste(); //
- for (i=0; i<doc2.pageItems.length; i++){doc2.pageItems.position=doc.pageItems.position;} ; // restore position
And this one (found here) that I modified to round CMYK to the nearest 10 but I need to deal with adding the colors of my PDF in the swatches and I don’t find how to do it in JS…
function roundColorValues(color) {
var col = color;
col.cyan = (Math.round((col.cyan)/10))*10;
col.magenta = (Math.round((col.magenta)/10))*10;
col.yellow = (Math.round((col.yellow)/10))*10;
col.black = (Math.round((col.black)/10))*10;
}
var idoc = app.activeDocument;
var sws = idoc.swatches;
for (i = 0; i<sws.length; i++) {
var sw = sws;
if (sw.color.typename == "CMYKColor")
roundColorValues (sw.color);
else if (sw.color.typename == "SpotColor") {
//$.writeln(sw.color.spot.getInternalColor());
roundColorValues (sw.color.spot.color);
//$.writeln(sw.color.spot.getInternalColor());
}
}
I have difficulties to build script able to do all that stuff in once, somebody can help me ?
Thanks !
Max