Skip to main content
tpk1982
Legend
May 10, 2016
Answered

Colllection of Fonts from Document

  • May 10, 2016
  • 4 replies
  • 1538 views

Hi,

Am using Illustrator CS6 on Mac. Is it possible to collect fonts whatever i used in the document by scripting? I got some scripts from this forum but not effective.

I aware the packaging option available in CC2014.

But i need this for CS6. Please help.

Regards,

Karthi

This topic has been closed for replies.
Correct answer Ten A

Here is an example to collect activeDocuments font:

function getFntsLst (doc){

     var xmlString = new XML(doc.XMPString);

     var fntFamily = xmlString.descendants("stFnt:fontFamily");

     var fntFace = xmlString.descendants("stFnt:fontFace");

  var fntFile = xmlString.descendants("stFnt:fontFileName");

     var lst = new Array();

     for (var i=0; i<fntFace.length(); i++)

  lst.push([fntFamily, fntFace, fntFile]);

     return lst;

  }

function main() {

  var dc = app.activeDocument;

  var dcPth = dc.path;

  var lst = getFntsLst (dc);

  var dst = new Folder(dcPth + '/DocumentFonts');

  var getFnts = function (string, dst) {

  var tb = String.fromCharCode(9);

  var lst = string.split(',');

  var pth, fl, nm;

  for (var i=0; i<lst.length; i++){

  pth = app.fonts.itemByName(lst+tb+lst[++i]).location;

  fl = File(pth);

  nm = dst + '/' + lst[++i];

  fl.copy(File(nm));

  }

  };

  if (!dst.exists) dst.create();

  var bt;

  bt = new BridgeTalk();

  bt.target = "indesign";

  bt.body = getFnts.toSource() + '("' + lst +'", "' + dst.path+'/'+dst.name + '")';

  bt.onResult = function (resultMsg) {

  $.writeln("Result = " + resultMsg.body);

  }

  bt.onError = function (errorMsg) {

  $.writeln("Error = " + errorMsg.body);

  }

  bt.send();

  }

main();

4 replies

Inspiring
May 11, 2016

Hi, I have write 3 scripts for collect ai document fonts years ago.

2 of them need Indesign(same as @Ten A)

ExtendScripts4AI-ID/AI_Package Fonts of Document with ID.jsx at master · moluapple/ExtendScripts4AI-ID · GitHub

ExtendScripts4AI-ID/AI_ID_Package Fonts of File with ID.jsx at master · moluapple/ExtendScripts4AI-ID · GitHub (This script do not need to open ai file)

and 1 need Illustrator only:

ExtendScripts4AI-ID/AI_PackageFonts v2.0.jsx at master · moluapple/ExtendScripts4AI-ID · GitHub (When run first time it will create a file which contains fonts info, and restart Illustrator.)

Hope this can be helpful to you.

tpk1982
tpk1982Author
Legend
May 12, 2016

Hi Ten A & moluapple,

Thank you so much to help me. All the scripts working fine after i reinstalled my Illustrator.

Regards,

Karthi

Ten A
Community Expert
Community Expert
May 11, 2016

Can you send me your AI documents?

tpk1982
tpk1982Author
Legend
May 11, 2016

Unfortunately it is a client file and not able to share, sorry. But i opened a new document, put some text frames and keyed some text. Then tried the above coding that also not collecting fonts.

Ten A
Community Expert
Community Expert
May 11, 2016

Here is a modified version:

(function () {

  var dc = app.activeDocument;

  var dcPth = dc.path;

  var lst = getFntsLst ();

  var dst = new Folder(dcPth + '/DocumentFonts');

  var getFnts = function (str, dst) { //Bridgetalk function

  var lst = str.split(',');

  var pth, fl, nm,num;

  for (var i=0; i<lst.length; i++){

  pth = app.fonts.itemByName(lst).location;

  fl = File(pth);

  num = pth.lastIndexOf("/");

  nm = dst + '/' + pth.substring(num+1);

  fl.copy(File(nm));

  }

  };

  if (!dst.exists) dst.create();

  var bt;

  bt = new BridgeTalk();

  bt.target = "indesign";

  bt.body = getFnts.toSource() + '("' + lst +'", "' + dst.path+'/'+dst.name + '")';

  bt.onResult = function (resultMsg) {

  $.writeln("Finished collect.");

  }

  bt.onError = function (errorMsg) {

  $.writeln("Error = " + errorMsg.body);

  }

  bt.send();

  function getFntsLst(){ //make document font list function

  var tmp = "";

  var fLst = [];

  var d = app.activeDocument;

  if (d.textFrames.length>0){

  for (var i=0;i<d.textFrames.length;i++){

  for (var j=0;j<d.textFrames.characters.length;j++){

  tmp = d.textFrames.characters.characterAttributes.textFont.family

  + "\t" + d.textFrames.characters.characterAttributes.textFont.style;

  if (fLst.join().indexOf(tmp)==-1){

  fLst.push(tmp);

  }

  }

  }

  } else {

  return "There are no textFrames.";

  }

  return fLst;

  }

})();

Probabley, It works...

Ten A
Community Expert
Community Expert
May 11, 2016

Yes, It need InDesign.

Illustrator dose not have propaties of font path, But InDesign has location property.

tpk1982
tpk1982Author
Legend
May 11, 2016

Thank you for your prompt reply.. but i tested 3 documents but not sure why the fonts are not collected..any suggestions

Larry G. Schneider
Community Expert
Community Expert
May 10, 2016

If you have the Creative Cloud, the Package command was the first piece of candy added to CS6 to get people to move to the subscription model.

tpk1982
tpk1982Author
Legend
May 10, 2016

Thank you for the reply. But in my organization we dont have creative cloud..is it we need to update CS6 again?

Ten A
Community Expert
Ten ACommunity ExpertCorrect answer
Community Expert
May 11, 2016

Here is an example to collect activeDocuments font:

function getFntsLst (doc){

     var xmlString = new XML(doc.XMPString);

     var fntFamily = xmlString.descendants("stFnt:fontFamily");

     var fntFace = xmlString.descendants("stFnt:fontFace");

  var fntFile = xmlString.descendants("stFnt:fontFileName");

     var lst = new Array();

     for (var i=0; i<fntFace.length(); i++)

  lst.push([fntFamily, fntFace, fntFile]);

     return lst;

  }

function main() {

  var dc = app.activeDocument;

  var dcPth = dc.path;

  var lst = getFntsLst (dc);

  var dst = new Folder(dcPth + '/DocumentFonts');

  var getFnts = function (string, dst) {

  var tb = String.fromCharCode(9);

  var lst = string.split(',');

  var pth, fl, nm;

  for (var i=0; i<lst.length; i++){

  pth = app.fonts.itemByName(lst+tb+lst[++i]).location;

  fl = File(pth);

  nm = dst + '/' + lst[++i];

  fl.copy(File(nm));

  }

  };

  if (!dst.exists) dst.create();

  var bt;

  bt = new BridgeTalk();

  bt.target = "indesign";

  bt.body = getFnts.toSource() + '("' + lst +'", "' + dst.path+'/'+dst.name + '")';

  bt.onResult = function (resultMsg) {

  $.writeln("Result = " + resultMsg.body);

  }

  bt.onError = function (errorMsg) {

  $.writeln("Error = " + errorMsg.body);

  }

  bt.send();

  }

main();