• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Listing all fonts used in a document?

Engaged ,
Jun 05, 2012 Jun 05, 2012

Copy link to clipboard

Copied

   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?

TOPICS
Scripting

Views

4.9K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Enthusiast , Jun 06, 2012 Jun 06, 2012

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) {

      

...

Votes

Translate

Translate
Adobe
Enthusiast ,
Jun 05, 2012 Jun 05, 2012

Copy link to clipboard

Copied

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;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2012 Jun 06, 2012

Copy link to clipboard

Copied

Hi Moluapple,

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 06, 2012 Jun 06, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 06, 2012 Jun 06, 2012

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jun 06, 2012 Jun 06, 2012

Copy link to clipboard

Copied

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

        }

    }

}


Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jun 07, 2012 Jun 07, 2012

Copy link to clipboard

Copied

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 instanceof File && fileList.hidden == false) {

               var doc = app.open(fileList);

               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.textRange.fillColor).search("Gray") != 1) {

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

               return

          }

     }

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jun 07, 2012 Jun 07, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 09, 2012 Jun 09, 2012

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
May 12, 2015 May 12, 2015

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Apr 24, 2016 Apr 24, 2016

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Apr 27, 2016 Apr 27, 2016

Copy link to clipboard

Copied

LATEST

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!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines