11 Replies Latest reply on Apr 27, 2016 8:46 AM by Silly-V

    Listing all fonts used in a document?

    jsavage77 Level 1

         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?

        • 1. Re: Listing all fonts used in a document?
          moluapple Level 3

          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; 
          }
          
          • 2. Re: Listing all fonts used in a document?
            vinoth_mannu Level 1

            Hi Moluapple,

             

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

            • 3. Re: Listing all fonts used in a document?
              moluapple Level 3

              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.

              • 4. Re: Listing all fonts used in a document?
                vinoth_mannu Level 1

                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.

                • 5. Re: Listing all fonts used in a document?
                  moluapple Level 3

                  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!');
                          }
                      }
                  }
                  


                  • 6. Re: Listing all fonts used in a document?
                    vinoth_mannu Level 1

                    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

                              }

                         }

                    }

                    • 7. Re: Listing all fonts used in a document?
                      jsavage77 Level 1

                      Out of curiosity, could XMP be used to also find objects by their name?

                      • 8. Re: Listing all fonts used in a document?
                        CarlosCanto Adobe Community Professional & MVP

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

                        • 9. Re: Listing all fonts used in a document?
                          siomosp

                          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.

                          Selected Fonts name.jpg

                          Any suggestions?

                          Thanks a lot

                          • 10. Re: Listing all fonts used in a document?
                            fredsky2014

                            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

                            • 11. Re: Listing all fonts used in a document?
                              Silly-V Level 4

                              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-b2f 1-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!