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
1 Correct answer
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 =
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
Copy link to clipboard
Copied
Check out my 'change fonts scripts' for batch processor.
— Kas
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)
{}
}
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
if (newFont != null) {
characterStyles
}
}
// 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;
}
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;
}
}
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?
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.
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
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 "]
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
if (newFont != null) {
characterStyles
}
}
// 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;
}
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!
Copy link to clipboard
Copied
This should do the job.

