Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Thanks! I think we need to append the fontstyle, only when it is not falling on the default categories like Regular, Italic, Bold, BoldItalic.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Copy link to clipboard
Copied
Hi JohnR-
Sorry, over a year later, I finally checked back on this thread and saw your request. I did indeed come up with a workable solution after some more tinkering, which I've posted below. It's pretty specific to the fairly controlled environment I'm working in - if you ran this on a document with a different set of paragraph styles from what we're using, you'd get errors - but the methodology should be applicable to other environments with some modifications. Hope it's useful to others.
var FindAppliedParagraphStyle=new Array()
var FindAppliedFont=new Array()
var FindAppliedFontStyle=new Array()
var ReplaceFontStyle=new Array()
//change all instances of Symbol font to Regular
app.findTextPreferences.appliedFont="Symbol"
app.changeTextPreferences.fontStyle="Regular"
app.changeText()
app.findTextPreferences = null; app.changeTextPreferences = null;
//define styles to be replaced.
FindAppliedParagraphStyle[0]="Abstract"; FindAppliedFont[0]="Helvetica Neue LT Std"; FindAppliedFontStyle[0]="Bold Italic"; ReplaceFontStyle[0]="66 Medium Italic";
FindAppliedParagraphStyle[1]="Abstract"; FindAppliedFont[1]="Helvetica Neue LT Std"; FindAppliedFontStyle[1]="Bold"; ReplaceFontStyle[1]="65 Medium";
FindAppliedParagraphStyle[2]="Abstract"; FindAppliedFont[2]="Helvetica Neue LT Std"; FindAppliedFontStyle[2]="Regular"; ReplaceFontStyle[2]="65 Medium";
FindAppliedParagraphStyle[3]="Para_Text"; FindAppliedFont[3]="Helvetica Neue LT Std"; FindAppliedFontStyle[3]="Italic"; ReplaceFontStyle[3]="56 Italic";
FindAppliedParagraphStyle[4]="Para_Text"; FindAppliedFont[4]="Helvetica Neue LT Std"; FindAppliedFontStyle[4]="Regular"; ReplaceFontStyle[4]="55 Roman";
FindAppliedParagraphStyle[5]="Flush_Left"; FindAppliedFont[5]="Helvetica Neue LT Std"; FindAppliedFontStyle[5]="Italic"; ReplaceFontStyle[5]="56 Italic";
FindAppliedParagraphStyle[6]="Flush_Left"; FindAppliedFont[6]="Helvetica Neue LT Std"; FindAppliedFontStyle[6]="Regular"; ReplaceFontStyle[6]="55 Roman";
FindAppliedParagraphStyle[7]="Bib_Reference"; FindAppliedFont[7]="Helvetica Neue LT Std"; FindAppliedFontStyle[7]="Italic"; ReplaceFontStyle[7]="56 Italic";
FindAppliedParagraphStyle[8]="Bib_Reference"; FindAppliedFont[8]="Helvetica Neue LT Std"; FindAppliedFontStyle[8]="Regular"; ReplaceFontStyle[8]="55 Roman";
FindAppliedParagraphStyle[9]="Figure_Leg_Cont"; FindAppliedFont[9]="Helvetica Neue LT Std"; FindAppliedFontStyle[9]="Italic"; ReplaceFontStyle[9]="56 Italic";
FindAppliedParagraphStyle[10]="Figure_Leg_Cont"; FindAppliedFont[10]="Helvetica Neue LT Std"; FindAppliedFontStyle[10]="Regular"; ReplaceFontStyle[10]="55 Roman";
FindAppliedParagraphStyle[11]="Figure_Legend"; FindAppliedFont[11]="Helvetica Neue LT Std"; FindAppliedFontStyle[11]="Italic"; ReplaceFontStyle[11]="76 Bold Italic";
FindAppliedParagraphStyle[12]="Figure_Legend"; FindAppliedFont[12]="Helvetica Neue LT Std"; FindAppliedFontStyle[12]="Regular"; ReplaceFontStyle[12]="75 Bold";
FindAppliedParagraphStyle[13]="TableLegend"; FindAppliedFont[13]="Helvetica Neue LT Std"; FindAppliedFontStyle[13]="Italic"; ReplaceFontStyle[13]="56 Italic";
FindAppliedParagraphStyle[14]="TableLegend"; FindAppliedFont[14]="Helvetica Neue LT Std"; FindAppliedFontStyle[14]="Regular"; ReplaceFontStyle[14]="55 Roman";
FindAppliedParagraphStyle[15]="Table_Body"; FindAppliedFont[15]="Helvetica Neue LT Std"; FindAppliedFontStyle[15]="Italic"; ReplaceFontStyle[15]="56 Italic";
FindAppliedParagraphStyle[16]="Table_Body"; FindAppliedFont[16]="Helvetica Neue LT Std"; FindAppliedFontStyle[16]="Regular"; ReplaceFontStyle[16]="55 Roman";
//NOTE: new entries can be added by simply adding a new line at the end that follows the pattern laid out above
//loop through all the find/replaces above
for (i = 0; i < FindAppliedParagraphStyle.length; i++) {
//test to see if there are missing fonts.
try {fontLocs = app.activeDocument.fonts.everyItem().location;
//if not, break.
app.findTextPreferences = null; app.changeTextPreferences = null; alert("All missing fonts have been corrected."); break}
//if so, try to correct by running find/replaces with the criteria above.
catch (err) {
//clear find/change preferences
app.findTextPreferences = null; app.changeTextPreferences = null;
//find and replace missing fonts based on the search criteria in the array
//app.findPreferences.appliedParagraphStyle=FindAppliedParagraphStyle
app.findTextPreferences.appliedParagraphStyle=FindAppliedParagraphStyle
app.findTextPreferences.appliedFont=FindAppliedFont+" "+FindAppliedFontStyle
app.changeTextPreferences.fontStyle=ReplaceFontStyle
app.changeText();
}
}
//if all searches have been run and there are still missing fonts, alert the user
if (i==FindAppliedParagraphStyle.length)
{
app.findTextPreferences = null; app.changeTextPreferences = null;
alert("There are still missing fonts. Go to Type > Find Font to find them.");
}
Find more inspiration, events, and resources on the new Adobe Community
Explore Now