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

Changing Fonts via script

Explorer ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

my group of designers has been told that we are to no longer use the type 1 version of the font Whitney and to change all documents going forward to the open type font version. (they actually removed the (T1) font from the computer!)

so now all my old documents open with lots of type highlighted warning me that the font is missing. I can manually go thru and change every document when i open it using the built in "find font" multiple times because of the various weights. or with your help i can figure out a script that will do it for me.

It seems straight forward but when i go looking for an existing script to start from they all seem to run into some sort of roadblock...i haven't found a single one that claims to actually work (they all give up before accomplishing writing this script)

ideally this script would look for Whitney (T1) Bold and replace it with Whitney Bold

Whitney (T1) book and replace it with ....

and also do the same this in the style/character sheets

anybody up for the challenge?

scott

TOPICS
Scripting

Views

5.6K

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 , Jul 18, 2019 Jul 18, 2019

you can use this script to replace font of all Text, Character Styles, Paragraph Styles:

//Old Font

var oldFontName="Whitney (T1)"

var oldFontStyle="Bold"

//New Font

var newFontName= "Whitney";

var newFontStyle="Bold";

var myDoc = app.activeDocument;

//Replace font of Text

app.findTextPreferences=app.changeTextPreferences= NothingEnum.nothing; 

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 

app.findTextPreferences.appliedFont = oldFontName;

app.findTextPreferences.fontStyle =

...

Votes

Translate

Translate
Advocate ,
Jul 16, 2019 Jul 16, 2019

Copy link to clipboard

Copied

You can try find and replace thing just like this:

/////============

var myDoc = app.documents[0]

app.findTextPreferences=app.changeTextPreferences= NothingEnum.nothing;

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;

app.findTextPreferences.appliedFont = app.fonts.item("Times New Roman MT Std Bold");////Here you can specify your old font name

app.changeTextPreferences.appliedFont = app.fonts.item("Times New Roman Italic");////Here you can specify your NEW font name

myDoc.changeText();

/////============

Or else you can check out the link posted by Marijan Tompa (tomaxxi)

Best

Sunil

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
Guru ,
Jul 17, 2019 Jul 17, 2019

Copy link to clipboard

Copied

Check out my 'change fonts scripts' for batch processor.

— Kas

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 ,
Jul 18, 2019 Jul 18, 2019

Copy link to clipboard

Copied

you can use this script to replace font of all Text, Character Styles, Paragraph Styles:

//Old Font

var oldFontName="Whitney (T1)"

var oldFontStyle="Bold"

//New Font

var newFontName= "Whitney";

var newFontStyle="Bold";

var myDoc = app.activeDocument;

//Replace font of Text

app.findTextPreferences=app.changeTextPreferences= NothingEnum.nothing; 

app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing; 

app.findTextPreferences.appliedFont = oldFontName;

app.findTextPreferences.fontStyle = oldFontStyle;

app.changeTextPreferences.appliedFont =newFontName;

app.changeTextPreferences.fontStyle =newFontStyle;

myDoc.changeText(); 

var oStyle;

//Replace font of character styles

for(var i=0;i<myDoc.characterStyles.length;i++)

{

    oStyle=myDoc.characterStyles;

    try

    {

        var currentFont=oStyle.appliedFont ;

        if (oStyle.fontStyle != "" )

               currentFont = currentFont  + oStyle.fontStyle;

        if(currentFont==oldFontName+oldFontStyle)

        {

              oStyle.appliedFont =newFontName;

            if(newFontStyle !="")

              oStyle.fontStyle=newFontStyle;

        }

        

    }

    catch(e)

    {}

  

}

//Replace font of paragraph styles

for(var i=0;i<myDoc.paragraphStyles.length;i++)

{

    oStyle=myDoc.paragraphStyles;

    try

    {

        var currentFont=oStyle.appliedFont.fontFamily;

        if (oStyle.fontStyle != "" )

               currentFont = currentFont  + oStyle.fontStyle;

        if(currentFont==oldFontName+oldFontStyle)

        {

              oStyle.appliedFont =newFontName;

            if(newFontStyle !="")

              oStyle.fontStyle=newFontStyle;

        }

        

    }

    catch(e)

    {}

  

}

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 ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

i pulled from the above and a few other scripts and have something that is mostly working...

what i am not able to address is if the document has a bulleted list. The bullets typeface are defined inside of the Paragraph style under bullets and numbering. this does not change when i change the font for character and/or paragraph fonts.

how do i change the font of "bullets and numbers"?

scott

here is what i have so far....

var fontList = [ 

    ["Janson Text\t55 Roman", "Whitney (OTF)\tBook"], 

    ["Whitney (T1)\tBook", "Whitney (OTF)\tBook"], 

   ["Whitney (T1)\tRegular", "Whitney (OTF)\tRegular"], 

    ["Whitney (T1)\tMedium", "Whitney (OTF)\tMedium"], 

    ["Whitney (T1)\tSemibold", "Whitney (OTF)\tSemibold"], 

    ["Whitney (T1)\tBold", "Whitney (OTF)\tBold"], 

    ["Whitney (T1)\tBlack", "Whitney (OTF)\tBlack"], 

    //

    ["Whitney (T1)\tBookItalic", "Whitney (OTF)\tBookItalic"], 

    ["Whitney (T1)\tRegularItalic", "Whitney (OTF)\tRegularItalic"], 

    ["Whitney (T1)\tMediumItalic", "Whitney (OTF)\tMediumItalic"], 

    ["Whitney (T1)\tSemiboldItalic", "Whitney (OTF)\tSemiboldItalic"], 

    ["Whitney (T1)\tBoldItalic", "Whitney (OTF)\tBoldItalic"], 

    ["Whitney (T1)\tBlackItalic", "Whitney (OTF)\tBlackItalic"]

   

]; 

     

main(); 

 

function main() { 

    try { // if something goes wrong in the try-catch block, the batch processor won't stop here. It will log the error message and continue further 

         

        var newFont, paragraphStyle, characterStyle, 

        doc = app.activeDocument, // The frontmost document 

        paragraphStyles = doc.allParagraphStyles, 

        characterStyles = doc.allCharacterStyles; 

         

     

 

        // Change in character styles 

        for (var c = 0; c < characterStyles.length; c++) { 

            characterStyle = characterStyles

            newFont = getNewFont(characterStyles.appliedFont + "\t" + characterStyles.fontStyle); 

            if (newFont != null) { 

                characterStyles.appliedFont = newFont; 

            } 

        } 

   

    // Change in paragraph styles 

        for (var p = 0; p < paragraphStyles.length; p++) { 

            paragraphStyle = paragraphStyles

            newFont = getNewFont(paragraphStyle.appliedFont.name); 

            if (newFont != null) { 

                paragraphStyle.appliedFont = newFont; 

            } 

        } 

         

        for (var i = 0; i < fontList.length; i++) { 

            var changed; 

            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING; 

            app.findTextPreferences.appliedFont = fontList[0]; 

            app.changeTextPreferences.appliedFont = fontList[1]; 

            changed = doc.changeText(); 

            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING; 

        } 

 

    } 

    catch(err) { // if an error occurs, catch it and write the  document's name, error message and line# where it happened into the log 

        gErrorLog.push(doc.name + " - " + err.message + ", line: " + err.line); 

    } 

 

function getNewFont(oldFontName) { 

    var newFont = null; 

     

    for (var p = 0; p < fontList.length; p++) { 

        if (oldFontName == fontList

[0]) { 

            newFont = app.fonts.itemByName(fontList

[1]); 

            if (!newFont.isValid) { 

                newFont = null; 

            } 

            break; 

        } 

    } 

 

    return newFont; 

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 ,
Jul 22, 2019 Jul 22, 2019

Copy link to clipboard

Copied

You must update process of

  // Change in paragraph styles

//Add this script replace font of bullet

  if(paragraphStyle.bulletsAndNumberingListType !=ListType.NO_LIST)

  {            

            newFont = getNewFont(paragraphStyle.bulletChar.bulletsFont.name);

            if (newFont != null) {

                paragraphStyle.bulletChar.bulletsFont = newFont;

            }            

   }

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

works perfect....

found one more place i'm falling short though...

my script does not change the font if a style had been applied and then the font manually changed to override the style

for instance italicizing a small section of body copy

is this an easy fix?

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 ,
Jul 23, 2019 Jul 23, 2019

Copy link to clipboard

Copied

I can't understand your case can't replace font.

If you set style and manually override font of style,

you must set 2 fonts in fontList , it will replace.

If you can't fix, you must upload file can't replace.

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 ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

I'm sorry i was not more clear...

if i apply a paragraph style and then manually make a change within the paragraph


(override the paragraph style to make a small section within the paragraph be italic or bold)

the altered section will not be changed

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 ,
Jul 25, 2019 Jul 25, 2019

Copy link to clipboard

Copied

I think your source can process.["Whitney (T1)\tRegular", "Whitney (OTF)\tRegular"]

If paragraph set font is : "Whitney (T1)\tRegular" by paragraph style.

you manually : set font style to italic

In your fontlist , you setting 2 fonts name:

["Whitney (T1)\tRegular", "Whitney (OTF)\tRegular"]

["Whitney (T1)\titalic", "Whitney (OTF)\titalic "]

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 ,
Jul 26, 2019 Jul 26, 2019

Copy link to clipboard

Copied

I'm fairly new to scripting and don't use it nearly enough so i very much appreciate your patience...

the script as i current have it is changing the (1)character styles, (2)the paragraph styles, and (3)the bullet style but i do not see where it is changing anything that is not defined by one of those three items.

if i have a document that the designer did not use any styles (everything is a manual modification to the "Basic" paragraph style) the way this is written, it will not change anything

scott

============================================================================================

var fontList = [ 

    ["Janson Text\t55 Roman", "Whitney (OTF)\tBook"], 

    ["Whitney (T1)\tBook", "Whitney (OTF)\tBook"], 

   ["Whitney (T1)\tRegular", "Whitney (OTF)\tRegular"], 

    ["Whitney (T1)\tMedium", "Whitney (OTF)\tMedium"], 

    ["Whitney (T1)\tSemibold", "Whitney (OTF)\tSemibold"], 

    ["Whitney (T1)\tBold", "Whitney (OTF)\tBold"], 

    ["Whitney (T1)\tBlack", "Whitney (OTF)\tBlack"], 

    //

    ["Whitney (T1)\tBookItalic", "Whitney (OTF)\tBookItalic"], 

    ["Whitney (T1)\tRegularItalic", "Whitney (OTF)\tRegularItalic"], 

    ["Whitney (T1)\tMediumItalic", "Whitney (OTF)\tMediumItalic"], 

    ["Whitney (T1)\tSemiboldItalic", "Whitney (OTF)\tSemiboldItalic"], 

    ["Whitney (T1)\tBoldItalic", "Whitney (OTF)\tBoldItalic"], 

    ["Whitney (T1)\tBlackItalic", "Whitney (OTF)\tBlackItalic"]

   

]; 

     

main(); 

 

function main() { 

    try { // if something goes wrong in the try-catch block, the batch processor won't stop here. It will log the error message and continue further 

         

        var newFont, paragraphStyle, characterStyle, 

        doc = app.activeDocument, // The frontmost document 

        paragraphStyles = doc.allParagraphStyles, 

        characterStyles = doc.allCharacterStyles; 

         

     

 

        // Change in character styles 

        for (var c = 0; c < characterStyles.length; c++) { 

            characterStyle = characterStyles

            newFont = getNewFont(characterStyles.appliedFont + "\t" + characterStyles.fontStyle); 

            if (newFont != null) { 

                characterStyles.appliedFont = newFont; 

            } 

        } 

   

    // Change in paragraph styles 

        for (var p = 0; p < paragraphStyles.length; p++) { 

            paragraphStyle = paragraphStyles

            newFont = getNewFont(paragraphStyle.appliedFont.name); 

            if (newFont != null) { 

                paragraphStyle.appliedFont = newFont; 

            } 

        } 

         

//Add this script replace font of bullet

  if(paragraphStyle.bulletsAndNumberingListType !=ListType.NO_LIST)

  {           

            newFont = getNewFont(paragraphStyle.bulletChar.bulletsFont.name);

            if (newFont != null) {

                paragraphStyle.bulletChar.bulletsFont = newFont;

            }           

   }         

         

        for (var i = 0; i < fontList.length; i++) { 

            var changed; 

            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING; 

            app.findTextPreferences.appliedFont = fontList[0]; 

            app.changeTextPreferences.appliedFont = fontList[1]; 

            changed = doc.changeText(); 

            app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING; 

        } 

 

    } 

    catch(err) { // if an error occurs, catch it and write the  document's name, error message and line# where it happened into the log 

        gErrorLog.push(doc.name + " - " + err.message + ", line: " + err.line); 

    } 

 

function getNewFont(oldFontName) { 

    var newFont = null; 

     

    for (var p = 0; p < fontList.length; p++) { 

        if (oldFontName == fontList

[0]) { 

            newFont = app.fonts.itemByName(fontList

[1]); 

            if (!newFont.isValid) { 

                newFont = null; 

            } 

            break; 

        } 

    } 

 

    return newFont; 

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 ,
Dec 08, 2021 Dec 08, 2021

Copy link to clipboard

Copied

Does anyone have a currently working script to change fonts from Type 1 to OpenType?

Especially in all paragraph formats.

Thank you!

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 ,
Feb 12, 2022 Feb 12, 2022

Copy link to clipboard

Copied

LATEST

This should do the job.

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