Site logo

Font

Missing Font Replacement by Marc

Document.prototype.changeMissingFontsBy = function(/*str|Font*/fontOrFontName)
{
var asFont = function(/*var*/f)
     {
     if (!f) return null;
     if (typeof f == 'string') f = app.fonts.item(f);
     if (f.constructor != Font) return null;
     return(f);
     };
 
var missing = function(/*Font*/f)
     {return ( f.status != FontStatus.INSTALLED );}     
     
var substFont = asFont(fontOrFontName);
if ((!substFont) || missing(substFont))
     {
     alert( "["+ fontOrFontName + "] is not installed!" );
     return;
     }
 
var changeMissingFont = function(obj)
     { //  : any object with appliedFont prop
     var f = asFont(obj.appliedFont);
     if ((!f) || (!missing(f))) return;
 
     try{obj.appliedFont = substFont;}
     catch(ex){}
     };
     
var scope = this.allCharacterStyles
     .concat(this.allParagraphStyles)
     .concat(this.stories.everyItem().textStyleRanges.everyItem().getElements());
 
var s;
while ( s=scope.shift() ) changeMissingFont(s);
}
 
// test
app.activeDocument.changeMissingFontsBy("Times New Roman");

Or click here to download it.

See also:
Find/change missing font by Marijan Tompa
FontGlyphCount by Marc Autret — Fast Glyph Counter
Change fonts CSV script