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

How can I find existence of missing fonts using java script?

New Here ,
Jan 21, 2020 Jan 21, 2020

Copy link to clipboard

Copied

Hello,

Missing font information with exclamation is shown up in a Missing Fonts dialog in menu Type - Resolve Missing Fonts.

Could you please tell me how to find this informaion using Java Script?

app.textFonts seems not to have this Missing Fonts information.

Thanks in advance.

TOPICS
Scripting

Views

1.8K

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

Community Expert , Jan 22, 2020 Jan 22, 2020

Sorry, I tried to get Applications fonts and It includes missing fonts when we open documents that have missing fonts.
So, We need to get Applications fonts list before the document opened.

 

BTW, The contents length sometimes throw incorrect length(ExtendScript does not parse Surrogate Pair), I think to reference characters.length is better.

Votes

Translate

Translate
Adobe
Community Expert ,
Jan 21, 2020 Jan 21, 2020

Copy link to clipboard

Copied

Illustrator's Scripting DOM does not have missing font collection.
You need to list up documents font list and compare it with apps font list.

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
New Here ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Thank you for your kind reply.

I'd like to confirm what you mean.

documents font list : activeDocument.textFrames[i].story.textRange.characters[j].textFont.name.

apps font list : app.textFonts[i].name.

If my understanding is correct, app.textFont[i].name includes the Missing-Fonts family and name.

Under my condition, KozGoPro-Regular is indicated as a Missing Font in Missing Fonts dialog

with exclamation.

app.textFont[i].family or name reply KozGoPro-Regular as one of 600s fonts name.

My check script is following:

 

var appFontList = [];
var appFontLen = app.textFonts.length;

for ( var i = 300; i < appFontLen; i++ ) {
    appFontList[ app.textFonts[ i ].name ] = 0;
}

var docFontList = [];
var docFontLen = activeDocument.textFrames.length;

for ( i = 0; i < docFontLen; i++ ) {
    var charLen = activeDocument.textFrames[ i ].story.textRange.contents.length;
    for ( var j = 0; j < charLen; j++ ) {
        var fontName = app.activeDocument.textFrames[ i ].story.textRange.characters[ j ].textFont.family;       
        if ( appFontList[ fontName ] != 0 ) {
            alert( fontName );
        }
    }
}

 

Could you give us any advice?

Illustrator CC2020

 

 

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
Advocate ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Are you just trying to see a full list of missing fonts? To do so, go to "Type"..."Find Font", then in the dialog box, select "Save List". It will save a text file which you can open to view the missing fonts.

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
New Here ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Thank you for your kind support.

Final purpose of scripting is to convert text to outline.

Beforhand the converting, want to check if missing font exists or not.

 

DOM has not missing font collection.

app.textFonts seems to have missing font collection.

If this is correct, comparing app font lists and document font lists is no meaning to check.

 

Current situation is above.

 

My posted code has some mispoints.

Retry to post. Very sorry.

 

var appFontList = [];

for ( var i = 0; i < app.textFonts.length; i++ ) {
    appFontList[ app.textFonts[i].name ] = 0;
}

var docFontList = [];

for ( i = 0; i < activeDocument.textFrames.length; i++ ) {
    var charLen = activeDocument.textFrames[i].story.textRange.contents.length;
    for ( var j = 0; j < charLen; j++ ) {
        var fontName = app.activeDocument.textFrames[i].story.textRange.characters[j].textFont.name;
        if ( appFontList[ fontName ] != 0 ) {
            alert( fontName );
        }
    }
}

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 ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Sorry, I tried to get Applications fonts and It includes missing fonts when we open documents that have missing fonts.
So, We need to get Applications fonts list before the document opened.

 

BTW, The contents length sometimes throw incorrect length(ExtendScript does not parse Surrogate Pair), I think to reference characters.length is better.

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
New Here ,
Jan 22, 2020 Jan 22, 2020

Copy link to clipboard

Copied

Thanks too much.

>get Applications fonts list before the document opened.

I couldn't reached this conclusion.

Information on surrogate pair is also appreciated.

 

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
Advocate ,
Nov 26, 2021 Nov 26, 2021

Copy link to clipboard

Copied

Bonjour!

Peut-être que je peux aider avec ce script ?

// JavaScript Document for Illustrator
// missing font.js
// Thu, 18 November 2021 08:50:59 GMT
// Modif Landry R
/* Donne la liste des polices utilisées dans le document actif
   ainsi que la liste des polices qui n'existent pas dans le système.*/
// INIT ---------------
  var info = false; var sep = ";"; var fntInfoStr;
//---------------------
  var docRef = app.activeDocument;
  var docName = docRef.name;
  var dest = File.decode(docRef.fullName); // alert(dest)
      docRef.close(SaveOptions.DONOTSAVECHANGES);
      docRef = null;
  var doctest = app.documents.add();
  var sFontNames = getSysFonts(sep); // string
      docRef = open(new File(dest));
      //alert(sFontNames.substring(0,200))
  var fonts = getFntsLst(docRef); // array
  var result = [];
      for (var i = 0;i < fonts.length; i++) {
        if (sFontNames.indexOf(sep+fonts[i]+sep) != -1) {
          st += fonts[i] + " <found in system>\r";
        }
        else  {
          st += fonts[i] + " >not found in system<\r";
          result.push(i+1)
        }
      }
        var defaut = result.length > 0  ? "DEFAULT!! ligne(s) "+result.join(' ')+"\r" : "";
        alert(defaut+st);
        if (info) {
              docRef.artboards.setActiveArtboardIndex(0)
          var abRect = docRef.artboards[0].artboardRect;
          var origX = abRect[0], origY = abRect[1], H =  abRect[1]-abRect[3];
          var rectRef = docRef.pathItems.rectangle(origY+H,origX-950,650, 1200);
          var text = docRef.textFrames.pointText([origX-200,origY-20]);
              text.contents = fonts.join("\r");
              text = docRef.textFrames.areaText(rectRef);
              text.contents = sFontNames.replace(/;/g," "); // sysFtStr
              text.textRange.size = 11.5;
              text = docRef.textFrames.pointText([origX-200,origY-120]); // st
              text.contents = defaut+st;
              text = docRef.textFrames.pointText([origX-200,origY-320]); // fntInfoStr
              text.contents = fntInfoStr;
        }
        doctest.close(SaveOptions.DONOTSAVECHANGES);
// -------
function getFntsLst (doc){
// return list array fonts doc
    var xmlString = new XML(doc.XMPString);
    var fontsInfo = xmlString.descendants("stFnt:fontName");
        fntInfoStr = fontsInfo.toString();
    var lst = [];
      for (var i = 0; i < fontsInfo.length(); i++) {
        lst.push(fontsInfo[i]);
      }
    return lst;
}
// -------
function getSysFonts(sep){
// string list fonts system (sep space))
  var sFontNames = sep;
  var iCount = app.textFonts.length;
    for(j = 0; j < iCount; j++) {
      sFontNames += textFonts[j].name+sep;
    }
  return sFontNames;
}
// -------

René

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 06, 2024 Jun 06, 2024

Copy link to clipboard

Copied

Merci for you script. It is very helpful to identify Illustrator documents with missing or wrong fonts.
I would like to understand why the docRef needs to be closed and then opened again to get the correct result. 

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 10, 2024 Jun 10, 2024

Copy link to clipboard

Copied

LATEST

@Stefan Rakete

The list of font names is taken from the document metadata XMP, so it will only be correct when the document is saved.

 

Probably closing and opening it again is a way to be sure that the XMP is up-to-date. I sometimes substitute that by checking Document.saved.

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