Here you go, one Javascript to fit. It creates a new document in CMYK mode, with the required number of artboards. (Getting that right took more time than writing the entire drawing stuff, too!)
You can change the page and rectangle sizes near the top; adjust to fit your needs.
I do hope, though, you are using CS4 or older -- I can't test but I bet it will draw everything upside down for CS5!
//DESCRIPTION:Make Color Book From CSV
// A Jongware Script 15-Jan-2011
// Large parts for reading CSV shamelessly pilfered from
// Muppet Mark, http://forums.adobe.com/message/2877951#2877951
// The CSV is assumed to have this format:
// Cyan,Magenta,Yellow,Black
// separated by commas, color values in percents (so 100 = full)
// This sets up a landscape A4 document. Adjust for your own needs.
// My values are in mm, so they need converting to points for Illy.
// You can also enter sizes in inches -- use in2pt for that, as in:
// width = in2pt (8.5)
// height = in2pt (11);
// to set Letter size
// or use cm2pt(..) if you prefer centimeters
// ... no need to convert points, so if you like these
// simply enter
// width = 800; // value is in points
width = mm2pt (297);
height = mm2pt (210);
// Size and distance per color rectangle
// The vertical distance needs to be enough for
// your by-line to fit.
rectwidth = mm2pt(20);
rectheight = mm2pt(15);
distancex = mm2pt (4);
distancey = mm2pt (8);
// These get recalculated to center the entire block
// of colors nicely on the page size.
leftoffset = 0;
topoffset = 0;
if (isOSX())
{
var csvFile = File.openDialog('Select a CSV File', function (f) { return !f.hidden && ((f instanceof Folder) || f.name.match(/\.csv$/i));} );
} else
{
var csvFile = File.openDialog('Select a CSV File','comma-separated-values(*.csv):*.csv;');
}
if (csvFile != null)
{
fileArray = readInCSV(csvFile);
var columns = fileArray[0].length;
// alert('CSV file has ' + columns + ' columns…');
var rows = fileArray.length;
// alert('CSV file has ' + rows + ' rows…');
if (columns == 4 && rows > 0)
{
doc = createDocument (fileArray.length);
if (doc)
drawRects (doc, fileArray);
else
alert ("Rectangle and Page Sizes do not add up!");
} else
{
alert ("CSV is not in the expected format");
}
}
function createDocument (numrects)
{
// How many rectangles in horizontal?
horzrange = Math.floor((width+distancex)/(rectwidth+distancex));
// And vertical?
vertrange = Math.floor((height+distancey)/(rectheight+distancey));
if (horzrange < 1 || vertrange < 1)
return null;
// How many artboards do we need?
numartb = Math.ceil (numrects/(horzrange*vertrange));
// alert ("We need "+numartb+" artboards");
leftoffset = (width+distancex-horzrange*(rectwidth+distancex))/2;
topoffset = (height+distancey-vertrange*(rectheight+distancey))/2;
doc = app.documents.add (DocumentColorSpace.CMYK, width, height, numartb, DocumentArtboardLayout.GridByCol);
return doc;
}
function drawRects (doc, array)
{
black = new GrayColor();
black.gray = 100;
xpos = 0;
ypos = 0;
artb = 0;
// alert (doc.artboards[artb].artboardRect);
for (i = 0; i < array.length; i++)
{
color = new CMYKColor();
try {
color.cyan = Number(array[0]);
color.magenta = Number(array[1]);
color.yellow = Number(array[2]);
color.black = Number(array[3]);
} catch (_)
{
alert ("Failed on line #"+i);
return;
}
rect = doc.pathItems.rectangle (doc.artboards[artb].artboardRect[1]-topoffset-ypos, doc.artboards[artb].artboardRect[0]+leftoffset+xpos, rectwidth, rectheight);
rect.strokeColor = black;
rect.strokeWidth = 0.5;
rect.fillColor = color;
t = doc.textFrames.add();
t.left = doc.artboards[artb].artboardRect[0]+leftoffset+xpos+rectwidth/2;
t.top = doc.artboards[artb].artboardRect[1]-topoffset-ypos-rectheight;
t.contents = array[0]+" / "+array[1]+" / "+array[2]+" / "+array[3];
t.paragraphs[0].justification = Justification.CENTER;
t.paragraphs[0].size = 8;
xpos += rectwidth + distancex;
if (xpos + rectwidth > width)
{
xpos = 0;
ypos += rectheight + distancey;
if (ypos+rectheight > height)
{
ypos = 0;
artb++;
}
}
}
}
function mm2pt (val)
{
return val*72/25.4;
}
function cm2pt (val)
{
return val*72/2.54;
}
function in2pt (val)
{
return val*72;
}
function isOSX()
{
return $.os.match(/Macintosh/i);
}
function readInCSV(fileObj)
{
var fileArray = new Array();
fileObj.open('r');
fileObj.seek(0, 0);
while(!fileObj.eof)
{
var thisLine = fileObj.readln();
if (thisLine.indexOf(',') > 0)
{
fileArray.push(thisLine.split(','));
}
}
fileObj.close();
return fileArray;
}