Skip to main content
Inspiring
June 5, 2012
Answered

Listing all fonts used in a document?

  • June 5, 2012
  • 3 replies
  • 5614 views

   As I understand it, TextFonts is a collection of all fonts available to Illustraot.  Is there a collection of all fonts used in the open document?  Or would I have to step through every textFrame an create that list myself?

This topic has been closed for replies.
Correct answer moluapple

Please find my script below, it gives me script log file in txt format. but this works only for single file i need this for the entire files in the folder

And also i need the script error log for the open type and true type only not for ATM fonts

#target illustrator

var inputFolder = Folder.selectDialog("Select a folder contains '*.eps' files ");
var Loginfo = new File(inputFolder + "/Font.info.txt");
Loginfo.open("w", "TEXT", "????");
if (inputFolder) {
     var fileList = inputFolder.getFiles('*.eps');
     for (var i = 0; i < fileList.length; i++) {
          if (fileList instanceof File && fileList.hidden == false) {
               var doc = app.open(fileList);
               doc.textFrames.length && writeLog(doc);
               doc.close(SaveOptions.DONOTSAVECHANGES);
          }
     }
}
Loginfo.close();

// load the library
function writeLog(a) {
if (ExternalObject.AdobeXMPScript == undefined) {
ExternalObject.AdobeXMPScript = new
ExternalObject("lib:AdobeXMPScript");
}

var ns = "http://ns.adobe.com/xap/1.0/t/pg/"; // Fonts namespace

var propName = "Fonts"; // property name
var fieldFontName = "stFnt:fontName"; // field name
var fieldFontType = "stFnt:fontType"; // field name
var msg = ""

//Create an XMPMeta object from the active documents XMPString:
var myXmp = new XMPMeta(app.activeDocument.XMPString);

var fontNumber = myXmp.countArrayItems(ns,propName); // activeDocument used font count

if (fontNumber !=0) // if there's at least 1 font, proceed
     {     
         for (i=1; i<=fontNumber; i++)
               {
                    var fontname = myXmp.getProperty(ns,propName + "[" + i + "]" + fieldFontName);
                    var fonttype = myXmp.getProperty(ns,propName + "[" + i + "]" + fieldFontType);
                    msg += i + ". " + fontname + " - " + fonttype + "\n";
                    Loginfo.writeln("File: " + a.name  +  fontname  +   fonttype );
               }
           //alert(fonttype)
           //if(fonttype == "Open Type"||"True Type"){
           //alert(msg,"Font details",);
            }
            //alert(msg);
     //}
//else 
}

Please advice us as i am not good in the scripting.


I don't know why and how you write error log, so I only add a single alert after all. "xmpString" and "XMP library" are two different methods, you only need one of then.

#target illustrator

var inputFolder = Folder.selectDialog("Select a folder contains '*.eps' files ");

if (inputFolder) {

    var fileList = inputFolder.getFiles('*.eps'),

        fontsInfo = [];

    loadXMPLibrary();

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

        if (fileList instanceof File && fileList.hidden == false) {

            fontsInfo.push(getFontsInfo(fileList));

        }

    }

    unloadXMPLibrary();

}

var Loginfo = new File(inputFolder + '/Font.info.txt');

Loginfo.open('w', 'TEXT', '????');

var info = fontsInfo.join('\n\n');

Loginfo.write(info);

Loginfo.close();

if (/(Open Type|TrueType)/.test(info)) {

    alert('Open Type / TrueType font found, see log file for details!')

}

function getFontsInfo(file) {

    var arr = ['File: ' + decodeURI (file.name)],

        xmpFile, oXmp, fontNumber, i, path, fontname, fonttype, ns = 'http://ns.adobe.com/xap/1.0/t/pg/';

    xmpFile = new XMPFile(file.fsName, XMPConst.UNKNOWN, XMPConst.OPEN_FOR_READ);

    oXmp = xmpFile.getXMP(); //Returns an XMPMeta object

    fontNumber = oXmp.countArrayItems(ns, 'xmpTPg:Fonts');

    xmpFile.closeFile(XMPConst.CLOSE_UPDATE_SAFELY);

    if (fontNumber) { // if there's at least 1 font, proceed

        for (i = 1; i <= fontNumber; i++) {

            path = XMPUtils.composeArrayItemPath(ns, 'xmpTPg:Fonts', i);

            fontname = oXmp.getStructField(ns, path, XMPConst.TYPE_FONT, 'fontName');

            fonttype = oXmp.getStructField(ns, path, XMPConst.TYPE_FONT, 'fontType');

            arr.push([i, '. ', fontname, '-', fonttype].join(''));

        }

    }

    return arr.join('\n');

}

function loadXMPLibrary() {

    if (!ExternalObject.AdobeXMPScript) {

        try {

            ExternalObject.AdobeXMPScript = new ExternalObject('lib:AdobeXMPScript');

        } catch (e) {

            alert('Unable to load the AdobeXMPScript library!');

            return false;

        }

    }

    return true;

}

function unloadXMPLibrary() {

    if (ExternalObject.AdobeXMPScript) {

        try {

            ExternalObject.AdobeXMPScript.unload();

            ExternalObject.AdobeXMPScript = undefined;

        } catch (e) {

            alert('Unable to unload the AdobeXMPScript library!');

        }

    }

}


3 replies

fredsky2014
Known Participant
April 25, 2016

hello all!

i'm using the moluapple solution to get the list of all used fonts in a document.

okay, but there is a issue when using the librairies (introduced with illustrator 2015)....

to create such a file :

- create a text with a fontname, select it and right click "add to librairy". now delete it, and drag and drop the added library.

when selecting this text, it appears as a linked file.

- now create another text with another font name; since it's a regular text, it is not linked.

here is a sample result of moluapple script :

(i modified lines 38 and 39 to obtain the font filename on the disk, which is mandatory for me:

var fontfilename = oXmp.getStructField(ns, path, XMPConst.TYPE_FONT, 'fontFileName');

arr.push([i, '. ', fontname, '-', fonttype, '=', fontfilename].join(''));

)

File: construction_lib.ai

1. BritannicBold-Open Type=BRITANIC.TTF

2. UCAAAA+AndrogyneMedium-Unknown=MyriadPro-Regular.otf

3. CCAAAA+AndrogyneMedium-Unknown=MyriadPro-Regular.otf

4. QDAAAA+AndrogyneMedium-Unknown=MyriadPro-Regular.otf

5. OOAAAA+BradleyHandITC-Unknown=MyriadPro-Regular.otf

font 1.) is the correct result from a regular text box, and all other are from different library items.

all other are a mess, because of librairies.

anyone can solve this irrating issue?

best,

fred

Silly-V
Legend
April 27, 2016

You're able to add character styles to the libraries, but that's not your workflow, right?

Ok, in the case of linked library files, they get put into a folder on Windows which typically looks like this:

C:\Users\<me>\AppData\Roaming\Adobe\Creative Cloud Libraries\LIBS\A8A47B2A53C42F760A490D45_AdobeID\creative_cloud\dcx\46dde17d-80d7-4a8d-b2f1-018a85273671\components\8c0f37b4-f968-4f4e-a299-b64e745d16d4.ai

This .ai file is the actual file which is created when I drag a text frame into the Libraries panel.

In its parent directory, there's a manifest file which is how you can match up the Libraries panel asset name "Artwork 4" with the goobledygook that is their random-generated file name.

You'd think it's now as easy as getting this flie's XMP and getting the font out of there - but not so fast- the Fonts property is absent from this file! So, if you don't mind opening the file and getting the font from the text frame itself or saving this file as a new temp file, say on the desktop, in order to populate its XMP properly, then you can get the font name! Yahoo!

Inspiring
May 12, 2015

Hello!

The script works great , alerting with the fonts used at active document

I would like to modify it a "little"

The goal is to add  a text box displaying the  selected fonts name,  next to the text box with the current font.

Any suggestions?

Thanks a lot

Inspiring
June 6, 2012

If your document have been saved, you can use this function:

function getUsedFonts (doc ){

   var xmlString = new XML(doc.XMPString);

   fontsInfo = xmlString.descendants("stFnt:fontName");

   var ln = fontsInfo.length(), arr = [];

   for (var i = 0; i<ln; i++){arr.push(fontsInfo)};

   return arr;

}

vinoth_mannu
Inspiring
June 6, 2012

Hi Moluapple,

I have some files saved in a particular folder can i get the fonts details in a text format?

Inspiring
June 6, 2012

What kind of details do you want? From "xmlString" you can get:

         <xmpTPg:Fonts>

            <rdf:Bag>

               <rdf:li rdf:parseType="Resource">

                  <stFnt:fontName>Arial-Black</stFnt:fontName>

                  <stFnt:fontFamily>Arial</stFnt:fontFamily>

                  <stFnt:fontFace>Black</stFnt:fontFace>

                  <stFnt:fontType>Open Type</stFnt:fontType>

                  <stFnt:versionString>Version 5.06</stFnt:versionString>

                  <stFnt:composite>False</stFnt:composite>

                  <stFnt:fontFileName>ariblk.ttf</stFnt:fontFileName>

               </rdf:li>

            </rdf:Bag>

         </xmpTPg:Fonts>

If you want process multiple files, you can load the XMP library to parse details instead of open every document with illustrator to get xmlString.