Skip to main content
DuanesSearchForKnowledge
Inspiring
March 11, 2013
Answered

changing text from helvetica to arial with javascript

  • March 11, 2013
  • 2 replies
  • 3812 views

I’m working with PDF files in illustrator and whenever the file uses Helvetica I have to change the font to Arial. This gets old when working with hundreds of illustrations. Can anyone tell me how I would go about changing all text that uses Helvetica bold to Arial bold and Helvetica Roman to Arial?

Would I loop through all the text frames and get the value of the font and use that value to change them or is there a more global way to go about this?

Any help would be appreciated,

Duane

This topic has been closed for replies.
Correct answer pixxxelschubser

DuanesSearchForKnowledge wrote:

… If there was a way to find the font used in the file and select thetext using that font it seems it would be possible to change it to one of these fonts. I dont know enough about it to know if it is possible or not.

Thanks for the info,

Duane

Look at this example:

if (app.documents.length > 0 ) {

    var doc = app.activeDocument;

    var aFont = (doc.textFrames[0].textRange.textFont)

    // You always need the correct internal text font name

    // change to regular, if bold

    if (aFont.name == textFonts.getByName("MyriadPro-Bold").name) { // I haven't Helvetica here, so I take this font instead

        doc.textFrames[0].textRange.textFont = textFonts.getByName("MyriadPro-Regular");

        }

    // try and have fun

}

2 replies

Inspiring
March 11, 2013

A more global way would be to use the app's 'Find Font' feature…? Im not a user of actions so you could test if it's recordable and you could use with actions and batch…

DuanesSearchForKnowledge
Inspiring
March 11, 2013

The Find Font is what i use now. I wanted to find a way to do it with ExtendScript quicker. I have found that my arial font I use is textFont[12] and the arial bold I use is textfont[14] on my system. If there was a way to find the font used in the file and select thetext using that font it seems it would be possible to change it to one of these fonts. I dont know enough about it to know if it is possible or not.

Thanks for the info,

Duane

pixxxelschubser
pixxxelschubserCorrect answer
Community Expert
March 12, 2013

DuanesSearchForKnowledge wrote:

… If there was a way to find the font used in the file and select thetext using that font it seems it would be possible to change it to one of these fonts. I dont know enough about it to know if it is possible or not.

Thanks for the info,

Duane

Look at this example:

if (app.documents.length > 0 ) {

    var doc = app.activeDocument;

    var aFont = (doc.textFrames[0].textRange.textFont)

    // You always need the correct internal text font name

    // change to regular, if bold

    if (aFont.name == textFonts.getByName("MyriadPro-Bold").name) { // I haven't Helvetica here, so I take this font instead

        doc.textFrames[0].textRange.textFont = textFonts.getByName("MyriadPro-Regular");

        }

    // try and have fun

}

Larry G. Schneider
Community Expert
March 11, 2013

You can create an Action to do this and in CS6 run the action by using the doScript construct.

DuanesSearchForKnowledge
Inspiring
March 11, 2013

Intriguing!!!

I am stuck with CS 5 for now. I assume this doScript construct is only available in CS6?

Thanks for the info,

Duane

Larry G. Schneider
Community Expert
March 11, 2013

For ExtendScript, yes. For AppleScript and VBS, no.