4 Replies Latest reply on Mar 5, 2015 4:13 PM by farottone

    Substitute fonts


      Hello all. I'm trying to script a way to replace fonts in CS6 but something is not right with how InDesign recognises fonts. Some fonts won't be substituted, regardless of what I do. I even selected a word with the font to replace, got the name with app.selection[0].appliedFont.name and then used that name to replace the font. With some fonts it works, with others it won't. Some fonts show (TT) in the name, others don't, so it's not that. Has anybody ever successfully coded a font replacer script? It seems like something is broken. Thanks in advance for any help.

        • 1. Re: Substitute fonts
          Laubender Adobe Community Professional & MVP

          Can you show an example for a font where this is not working?
          It's name you get, how you apply it.
          And some code of course…



          • 2. Re: Substitute fonts
            [Jongware] Most Valuable Participant

            Isn't this the long-time problem where a script cannot get access to a 'document font' if the font is not available?

            • 3. Re: Substitute fonts
              farottone Level 1

              Of course. So, in example, this a working command:


              app.findTextPreferences.appliedFont  = "BentonSansCond\tRegular";  app.changeTextPreferences.appliedFont  = "BentonSans Cond Regular\tRegular";


              I have other fonts that won't replace. One shows up, missing in the document, as Benton Sans, Book, the other is Lexia Dama (TT), Bold. I tried any possible combination ("Lexia Dama (TT)\tBold", "Lexia Dama\tBold", "LexiaDama\tBold", etc.) and it just wouldn't replace it. So I wanted to find out whether I was using the wrong font name or InDesign was acting out and to do so I created a script that takes the font of the selected text and changes every instance of that font to a different font, to check whether InDesign correctly picks up the font name from a selection:


              app.findTextPreferences.appliedFont  = app.selection[0].appliedFont.name; 

                  app.changeTextPreferences.appliedFont  = "BentonSans Book\tRegular"; 



              If I select a word and run the script, the correct font is recognised and every instance of that font is changed. Now following the same logic I tried to select a word using the missing font and then replacing every instance of that missing font with another font. Well, it doesn't work. I'm linking to a file containing an InDesign file with 2 text boxes and a script to test out. If I select the Benton Sans text, it gets replaced by a different font, if I select the other one nothing happens.

              Dropbox - Font Test.rar

              • 4. Re: Substitute fonts
                farottone Level 1

                Just to be clear, this script DOES work with missing fonts with no problem, it's specific fonts I'm talking about. It throws no exception for missing fonts and works perfectly with them, just not all of them.