Skip navigation
Currently Being Moderated

Listing all fonts used in a document?

Jun 5, 2012 12:33 PM

   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?

 
Replies
  • Currently Being Moderated
    Jun 5, 2012 7:38 PM   in reply to jsavage77

    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[i])}; 
       return arr; 
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 12:03 AM   in reply to moluapple

    Hi Moluapple,

     

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

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 1:38 AM   in reply to vinoth_mannu

    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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 3:28 AM   in reply to 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[i] instanceof File && fileList[i].hidden == false) {
                   var doc = app.open(fileList[i]);
                   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.

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 6, 2012 6:06 AM   in reply to vinoth_mannu

    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[i] instanceof File && fileList[i].hidden == false) {
                fontsInfo.push(getFontsInfo(fileList[i]));
            }
        }
        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!');
            }
        }
    }
    


     
    |
    Mark as:
  • Currently Being Moderated
    Jun 7, 2012 3:56 AM   in reply to moluapple

    Thanks for the reply,

     

    This works fine, I need litte adjustment in this script.

     

    I need the log file to be writen only for the Open type and true type fonts.

     

    ATM font is fine for us.

     

    In addition i have another script for Text in grayscale this gives the details of the color info of the eps files.

     

    Could you please combine both the script into a single script.

     

    In need the log file in single format.

     

    The text in gray scale is below

     

    #target illustrator

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

    var Loginfo = new File(inputFolder + "/Sep_preview.txt");

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

    if (inputFolder) {

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

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

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

                   var doc = app.open(fileList[i]);

                   doc.textFrames.length && writeLog(doc);

                   doc.close(SaveOptions.DONOTSAVECHANGES);

              }

         }

    }

    Loginfo.close();

     

    //This function is to check the text objects in the document whether it contains any color text (non black text).

    function writeLog(a) {

         var i = 0, text = a.textFrames, len = text.length;

         for (; i < len; i++) {

              if (String(text[i].textRange.fillColor).search("Gray") != 1) {

                   Loginfo.writeln("File: " + a.name + "   Text not in Black");

                   return

              }

         }

    }

     
    |
    Mark as:
  • Currently Being Moderated
    Jun 9, 2012 12:44 AM   in reply to jsavage77

    "objects" as in "pageItems"? No, it is not possible.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points