Skip to main content
Participating Frequently
January 15, 2015
Question

Is there a way to populate an InDesign document with Pantone colors from a .csv document?

  • January 15, 2015
  • 2 replies
  • 320 views

I have a CSV document that inputs copy information into various labels we have set up in InDesign, but we also have Pantone colors that we put into this document.  Currently, it just imports the color number and we manually change the color ourselves, but is there a way to automatically populate the colors into the document?

This topic has been closed for replies.

2 replies

Participating Frequently
January 29, 2015

Thanks so much Loic! I am still new to using scripts within InDesign. How would I go about getting this to function?

Loic.Aigon
Legend
January 16, 2015

Hi,

Here is some code you may want to play with

Array.prototype.contains =  function ( object )

{

  var i = 0, n = this.length;

  for ( i = 0 ; i < n ; i++ )

  {

  if ( this === object )

  {

  return true;

  }

  }

  return false;

}

function createLabels() {

  var filterFunction = function(file)

  {

  return /\.csv$/.test ( file.name );

  }

  var f = File.openDialog("Please select CSV Files…", filterFunction);

  var sep = "\t";

  var n = 0;

  var headers = [];

  var rows = [], row = [];

  var doc, m, pw,pb,ph, np, tf, tfo;

  var p;

  if ( !f) { return; }

  f.open("r");

  headers = f.readln().split(sep);

  while ( !f.eof ){

  row = f.readln().split(sep);

  row.length>1 && rows [ rows.length ]  = {contents:row[0], colorName:row[1]};

  }

  n = rows.length;

  if ( !n ) {

  alert("No data");

  return;

  }

  doc = app.documents.add();

  doc.documentPreferences.facingPages = false;

  m = doc.pages[0].marginPreferences;

  pb = doc.pages[0].bounds;

  while (n--) {

  row = rows;

  np = doc.pages.add();

  doc.importAdobeSwatchbookSpotColor ( row.colorName );

  tfo = {

  geometricBounds:[pb[0]+m.top, pb[1]+m.right, pb[2]-m.bottom, pb[3]-m.left],

  contents:row.contents,

  fillColor:doc.colors.itemByName ( row.colorName ),

  }

  tf = np.textFrames.add(tfo);

  }

  doc.pages[0].remove();

}

createLabels();

Sorry for not using the highlighting code option but it wasn't displaying the whole stuff :\

Loic

http://www.ozalto.com