Copy link to clipboard
Copied
I've got this bit of code from user moluapple - he was incredibly helpful in getting me started, but isn't going to continue working on this and I was wondering if anyone else would be willing to help further this bit of code.
The code works to collect fonts in an open Illustrator document. The issue I am having is that it only collects one font. Or sometimes it will collect a whole font family. But I haven't been able to get it to collect all of the fonts in the document.
I was hoping someone could put their finger on what I'm doing wrong.
function getUsedFonts (doc){
var xmlString = new XML(doc.XMPString),
fontFamily = xmlString.descendants("stFnt:fontFamily"),
fontFace = xmlString.descendants("stFnt:fontFace"),
ln = fontFace.length(), i = 0, arr = [];
for (; i<ln; i++){arr.push(fontFamily + '\t' + fontFace)};
return arr;
}
alert(getUsedFonts(activeDocument));
function main() {
var
doc = app.activeDocument,
docPath = doc.path,
arr = getUsedFonts (doc),
oFolder = new Folder(docPath + '/DocumentFonts'),
btMsg,
PackageFonts = function (string, oFolder) {
var arr = string.split(','), oPath, oFile, oName, i;
for (i=0; i<arr.length; i++){
oPath = app.fonts.itemByName(arr).location;
oFile = File(oPath);
oName = oFolder + '/' + arr.replace (' ', ' ').replace(' Regular', '') +
oPath.substring(oPath.lastIndexOf('.'), oPath.length);
oFile.copy(File(oName), true);
}
};
oFolder.create();
btMsg = new BridgeTalk();
btMsg.target = "indesign";
btMsg.body = PackageFonts.toSource() + '("' + arr +'", "' + oFolder + '")';
btMsg.onResult = function (resultMsg) {
$.writeln("Result = " + resultMsg.body);
}
btMsg.onError = function (errorMsg) {
$.writeln("Error = " + errorMsg.body);
}
btMsg.send();
}
main();
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Woah. You're amazing. This is almost perfect! I'm bowing down to your skillz