Skip navigation
Currently Being Moderated

Font Replacement

Sep 14, 2009 11:22 AM

I hope there is an easy solution to this problem.


I've got some 200 InDesign documents that are "missing" fonts.


When I iterate over document.fonts, I look into the status attribute, and if I find a font to be "NOT AVAILABLE", I would like to replace it with another.


Thusfar, I have been unable to find a simplistic means by which to accomplish this.


Pointers / advice?



  • Currently Being Moderated
    Sep 14, 2009 1:45 PM   in reply to jeffmlevy



    first you need to iterate CharacterStyles and ParagraphStyles collections and find these missing fonts in definitions and change it

    then you need to check again document's font collection and if you still have missing status in any font - you need to use Search&Replace to replace all what left in text




    Mark as:
  • Currently Being Moderated
    Sep 15, 2009 6:22 AM   in reply to jeffmlevy



    sorry for a little misunderstanding I forgot to mention something


    property AppliedFont in CharacterStyle could be undefined - because like in UserInterface - you can leave it unselected in CharacterStyle definition - like many other parameters - so when you are checking CharacterStyle which doesn't have selected Font - AppliedFont will be undefined


    but if you will check ParagraphStyles definitions - there is always AppliedFont


    so if CharacterStyles have undefined AppliedFont property - you can skip this CharacterStyle




    Mark as:
  • Currently Being Moderated
    Sep 15, 2009 7:01 AM   in reply to jeffmlevy

    jeffmlevy wrote:


    The good news is, the document.fonts at least shows me the font is not available. What I continue to be flummoxed by is how I traverse the document itself and find the text that references the missing font. If the paraStyles & charStyles have no mention of the missing font, how then am I supposed to identify it for replacement?

    like I said in my first post first step is to look at Char/ParaStyles definitions and then use Search&Replace to find font in text applied as local formatting


    there is:


    Property AppliedFont As Variant
        Member of InDesign.FindPreference
        The applied font. Either a Font object or the name of font family as Font, String or idNothingEnum enumerator




    myMissingFontName = "Otello"

    myIndi.FindPreferences.AppliedFont = myMissingFontName


    and you will get collection of all texts with this missing font applied

    jeffmlevy wrote:


    Based on your last reply, my assumption is that the 'undefined' characterStyle.appliedFont property may indeed be the font I'm missing, and if it is, I do not know how to identify the name/family of that missing font (alas, because charStyle.appliedFont is undefined, there's no property to query for a name or family).

    no - if AppliedFont of CharacterStyle is undefined - than this means that no font is selected in CharacterStyle definition




    Mark as:
  • Currently Being Moderated
    Sep 15, 2009 8:30 AM   in reply to jeffmlevy

    I don't know if it could help, but this solution works for me (ID CS4):


    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;
    var missing = function(/*Font*/f)
         {return ( f.status != FontStatus.INSTALLED );}     
    var substFont = asFont(fontOrFontName);
    if ((!substFont) || missing(substFont))
         alert( "["+ fontOrFontName + "] is not installed!" );
    var changeMissingFont = function(obj)
         { // <obj> : any object with appliedFont prop
         var f = asFont(obj.appliedFont);
         if ((!f) || (!missing(f))) return;
         try{obj.appliedFont = substFont;}
    var scope = this.allCharacterStyles
    var s;
    while ( s=scope.shift() ) changeMissingFont(s);
    // test
    app.activeDocument.changeMissingFontsBy("Times New Roman");




    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