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

Script to replace fonts in all documents, including master pages + colour replacement

Community Beginner ,
Sep 17, 2020 Sep 17, 2020

Copy link to clipboard

Copied

Hi,

 

Preface: I have a very rough understanding of javascript, so bear with me if my questions are very simple.

I have a bunch of documents I need to edit. For all of them, I know I need to change a font (with two different syles), and I need to do a colour replacement.

Here is some code I patched together:

for (var i = app.documents.length-1; i >= 0; i--) { 
    var doc = app.documents; 

fontChange();
function fontChange(){
    step1();
}

function step1(){
    //Tuffy Regular > Roboto Regular
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences = app.changeTextPreferences  = null;
    app.findTextPreferences.appliedFont  = "Tuffy";
    app.findTextPreferences.fontStyle  = "Regular";
    app.changeTextPreferences.appliedFont = "Roboto";
    app.changeTextPreferences.fontStyle = "Regular";
    app.activeDocument.pageItems.everyItem().locked = false;
    app.activeDocument.stories.everyItem().changeText();
    app.findChangeTextOptions.includeMasterPages = true;
}

fontChangeTwo();
function fontChangeTwo(){
    step2();
}

function step2(){
    //Tuffy Bold > Roboto Bold
    app.findTextPreferences = NothingEnum.nothing;
    app.changeTextPreferences = NothingEnum.nothing;
    app.findTextPreferences = app.changeTextPreferences  = null;
    app.findTextPreferences.appliedFont  = "Tuffy";
    app.findTextPreferences.fontStyle  = "Bold";
    app.changeTextPreferences.appliedFont = "Roboto";
    app.changeTextPreferences.fontStyle = "Bold";
    app.activeDocument.pageItems.everyItem().locked = false;
    app.activeDocument.stories.everyItem().changeText();
    app.findChangeTextOptions.includeMasterPages = true;
}
}

 

Problem 1) I thought the first two lines would allow me to run this in all my documents but it doesn't work.

Problem 2) For some reason, my InDesign refuses to recognise Roboto when I run the script. It replaces the font with "Roboto (otf)" and highlights the text in red. It works fine with other fonts. If I manually replace the text in red with "Roboto", it works fine.

I've had issues with Roboto for a while in InDesign, the only way I found to have it work is to NOT activate it on Adobe fonts and have it installed on my machine instead. 

Problem 3) The easiest one, I don't know how to do a colour replacement. I need to replace Adobe's pure black with another colour from my palette.

 

I would be super grateful if anyone could help with any of these problems.

 

Thanks in advance.

TOPICS
How to , Scripting

Views

997

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 2 Correct answers

Community Expert , Sep 17, 2020 Sep 17, 2020

You waver between a number of different approaches. I you want to iterate through the open documents and use app.activeDocument, you must activate (i.e.bring to the front) each document in turn. But there's no need for that (and it's slow bussiness). Instead you can talk to documents without activating them, see your amended script. below.

 

Some other comments: resetting the preferences is needed only once, you do that before the loop because doing it inside the loop is a waste of time. And to

...

Votes

Translate

Translate
Community Expert , May 20, 2023 May 20, 2023

I can see that manually changing those fonts isn't really an option. Two suggestions. The best solution would be to get the font that your customer uses. It's likely that their font, though it may have the ame name, has a different version number. InDesign is really as finicky as that. Secondly, if you can't get that font, ask Kasyan to add to his script a line so that a paragraph style's font is changed only if it matches a defined font. It's just a small addition.

 

All that said, Kasyan'r scr

...

Votes

Translate

Translate
Community Expert ,
Sep 17, 2020 Sep 17, 2020

Copy link to clipboard

Copied

You waver between a number of different approaches. I you want to iterate through the open documents and use app.activeDocument, you must activate (i.e.bring to the front) each document in turn. But there's no need for that (and it's slow bussiness). Instead you can talk to documents without activating them, see your amended script. below.

 

Some other comments: resetting the preferences is needed only once, you do that before the loop because doing it inside the loop is a waste of time. And to make a change in a document, there's no need to address its stories: simply target the document itself.

 

Hope this helps.

Peter

 

 

app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;

for (var i = app.documents.length-1; i >= 0; i--) {
  app.documents[i].pageItems.everyItem().locked = false;
  step1 (app.documents[i]);
  step2 (app.documents[i]);
}

function step1 (doc) {
  //Tuffy Regular > Roboto Regular
  app.findTextPreferences.appliedFont  = "Tuffy";
  app.findTextPreferences.fontStyle  = "Regular";
  app.changeTextPreferences.appliedFont = "Roboto";
  app.changeTextPreferences.fontStyle = "Regular";
  doc.changeText();
}


function step2 (doc) {
  //Tuffy Bold > Roboto Bold
  app.findTextPreferences.appliedFont  = "Tuffy";
  app.findTextPreferences.fontStyle  = "Bold";
  app.changeTextPreferences.appliedFont = "Roboto";
  app.changeTextPreferences.fontStyle = "Bold";
  doc.changeText();
}

 

 

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 Expert ,
Sep 17, 2020 Sep 17, 2020

Copy link to clipboard

Copied

And there is a version that doesn't use a loop:

 

 

app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.documents.everyItem().pageItems.everyItem().locked = false;

app.findTextPreferences.appliedFont  = "Tuffy\tRegular";
app.changeTextPreferences.appliedFont  = "Roboto\tRegular";
app.documents.everyItem().changeText();

app.findTextPreferences.appliedFont  = "Tuffy\tBold";
app.changeTextPreferences.appliedFont  = "Roboto\tBold";
app.documents.everyItem().changeText();

 

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 ,
Sep 17, 2020 Sep 17, 2020

Copy link to clipboard

Copied

Thank you Peter, it works perfectly and it even solved my font problem! I'll do some research about changing font colours another time, I'm sure I can figure it out 🙂 

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 ,
Sep 24, 2020 Sep 24, 2020

Copy link to clipboard

Copied

It looks like I can't quite figure out how to change the colour everywhere in my document...

I added to the code to replace font colours: 

app.findTextPreferences = app.changeTextPreferences = null;
app.findChangeTextOptions.includeMasterPages = true;
app.documents.everyItem().pageItems.everyItem().locked = false;

app.findTextPreferences.appliedFont  = "Tuffy\tRegular";
app.changeTextPreferences.appliedFont  = "Roboto\tRegular";
app.documents.everyItem().changeText();

app.findTextPreferences.appliedFont  = "Tuffy\tBold";
app.changeTextPreferences.appliedFont  = "Roboto\tBold";
app.documents.everyItem().changeText();

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.strokeColor = "Black"; 
app.changeTextPreferences.strokeColor = "[other colour]"; 
app.documents.everyItem().changeText();

app.findTextPreferences = app.changeTextPreferences = null;

app.findTextPreferences.fillColor = "Black"; 
app.changeTextPreferences.fillColor = "[other colour]"; 
app.documents.everyItem().changeText();

 

This works perfectly. However, I'd like to also replace pure black from shapes and table cells. I tried "

app.findObjectPreferences.fillColor" but that didn't work. Any idea how to achieve this?

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 Expert ,
Sep 24, 2020 Sep 24, 2020

Copy link to clipboard

Copied

For cells you do something different because they're not objects (not objects that you can search anyway). Do something like this:

app.documents[0].tables.everyItem().cells.everyItem().fillColor = 'some fill';

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 ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Hey Peter,
This script just seems to cycle through and change the preferences, but doesn't replace any fonts in the document.
I'm going mad trying to get this feature to work in a script!

 

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 Expert ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

There are various versions in this thread. Please show the version that you use.

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 ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

I tried both of your scripts posted here and neither is changing any fonts for me.

Thanks for replying 🙂 

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 Expert ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

Are the font and style names spelled correctly?

The posted scripts change only local overrides, not the fonts in paragraph and/or character styles.

Maybe post (part of) your document. It's a simple script, it's not clear what goes wrong.

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 ,
May 18, 2023 May 18, 2023

Copy link to clipboard

Copied

I will tomorrow, I'm away from work for now.

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 ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

I appreciate your time, thanks.
I attach the document below. I'm trying to replace the fiont "Merriwaether (OTF)" with "Merriweather".

The script you provided seems to run OK, and cycles the properties through the Find-Change dialog box, but no fonts are changed in the document.
It's really frustrating, as this should be a built-in feature of the app really.

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 Expert ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

Ah, that one -- the dreaded (OTF) in the font's name. (TT) in the fiont's name is just as bad. That the script doesn't work on fonts with (OTF) or (TT) in their name is caused by an InDesign bug. You can see that as follows: run the script, then open the Find/Change window. You'll see that the font and style names appear correctly in the panels:

PeterKahrel_0-1684503651410.png

Now click in the Find Format panel, then select the Basic Character Format tab. You'll see theat the font name isn't there: that's the problem.

PeterKahrel_1-1684503712637.png

It's in fact a scripting bug, for if you enter the font and style names in the window manually, the replacement works fine. But using the Find/replace Font window is quicker for this type of font.

 

The problems with (OTF) and (TT) appearing in font names are complex. Try to avoid them as much as possible by making sure that you have the same fonts as those that the other person used. Identical font names aren't good enough: the font version numbers must match as well.

 

Sorry I can't be of more help.

 

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 ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

The problem is, I get hundreds of files to typeset and the source files have this (OTF) font applied, but the customer asks for the non-(OTF) version in the returned files.
Every book I get I have to trudge through and change all the fonts.

I have also tried the Change fonts CSV script from Kasyan Servetsky.
This one replaces the (OTF) with the normal font but then replaces all the other fonts in the book with Merriweather as well!

I'm using the following in the .csv file:
Merriweather (OTF)\tRegular;Merriweather\tRegular
Merriweather (OTF)\tItalic;Merriweather\tItalic
Merriweather (OTF)\tBold;Merriweather\tBold

 

 

/* Copyright 2022, Kasyan Servetsky
September 11, 2022
Written by Kasyan Servetsky
e-mail: askoldich@yahoo.com */
//======================================================================================
//$.level = 2;
var scriptName = "Change fonts CSV - 2.2",
csvFileName = "Change fonts list.csv", // CSV file name
doc, fontList,
progressBar, progressTxt,
countParStyles = countCharStyles = countFC = countTsrApplied = 0,
debugMode = true, // for debugging only true | false
args = [],
useArgs = false,
set = GetDialogSettings(),
calledFromBatchProcessor = CalledFromBatchProcessor();
 
if (calledFromBatchProcessor) { // called as a 'secondary' script from the batch processor
if (typeof g.arguments != "undefined") {
useArgs = true;
args = NormalizeArgs(g.arguments);
}
 
if (g.doc != null) { // If the script is called from the batch processor and the g.doc variable is sent from it, the doc variable is set to g.doc.
doc = g.doc; // With the all open documents option selected, make sure to use g.doc variable to send the current document from the batch processor to this script otherwise, it will not work correctly.
Main();
}
}
else { // called as a 'regular' script
PreCheck();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function Main() {
try {
var report, csvFile,
startTime = new Date();
 
// CSV file
if (calledFromBatchProcessor) {
if (useArgs) {
g.WriteToFile("The arguments file is used: '" + decodeURI(g.argumentsFile.fsName));
fontList = args;
}
else {
csvFile = GetCsv();
if (csvFile == null) {
g.WriteToFile("ERROR: The CSV file '" + csvFileName + "' is missing.");
return;
}
else {
g.WriteToFile("The CSV file is used: '" + decodeURI(csvFile.fsName));
fontList = ReadCsvData(csvFile); // global
}
}
}
else { // used as a stanalone script
csvFile = GetCsv(); // already checked in PreCheck
fontList = ReadCsvData(csvFile); // global
}
 
// Progress bar
if (!calledFromBatchProcessor) {
var progressWin = new Window("window", scriptName);
progressBar = progressWin.add("progressbar", undefined, 0, undefined); // global
progressBar.preferredSize.width = 600;
progressTxt = progressWin.add("statictext", undefined, ""); // global
progressTxt.alignment = "fill";
progressWin.show();
}
 
// Change in paragraph styles
if (set.parStyles) ProcessParStyles();
 
// Change in character styles
if (set.charStyles) ProcessCharStyles();
 
// Find - change
if (set.findChange) ProcessFindChange();
 
// Text style ranges
if (set.textStyleRanges) ProcessTextStyleRanges();
 
// Finish
if (!calledFromBatchProcessor)progressWin.close();
var endTime = new Date();
var duration = GetDuration(startTime, endTime);
 
if (countParStyles == 0 && countCharStyles == 0 && countFC == 0 && countTsrApplied == 0) {
report = "No changes have been made to the document.";
}
else {
report = "Changed fonts in " + countParStyles + 
" paragraph style" + ((countParStyles == 1)  ? ", " : "s, ") + 
countCharStyles + " character style" + ((countCharStyles == 1)  ? "," : "s,") + 
" and " + (countFC + countTsrApplied) + " instance" + 
(((countFC + countTsrApplied) == 1)  ? "" : "s") + 
" of locally formatted text (via find-change: " + countFC + ", and via text style ranges: " + countTsrApplied + 
")\n(time elapsed: " + duration + ")";
}
 
if (calledFromBatchProcessor) {
g.WriteToFile("\r" + report);
}
else {
alert(report, scriptName);
}
}
catch(err) { // if an error occurs, catch it and write the  document's name, error message and line# where it happened into the log
if (calledFromBatchProcessor) {
g.WriteToFile("ERROR: " + doc.name + " - " + err.message + ", Line: " + err.line + ", Time: " + GetTime());
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ProcessParStyles() {
var paragraphStyle, oldFont, newFont,
paragraphStyles = doc.allParagraphStyles;
 
if (calledFromBatchProcessor) {
g.WriteToFile("\nProcessing paragraph styles");
}
else {
progressTxt.text = "Processing paragraph styles";
progressBar.minvalue = 0;
progressBar.maxvalue = paragraphStyles.length;
}
 
for (var p = 1; p < paragraphStyles.length; p++) {
if (!calledFromBatchProcessor) progressBar.value = p;
paragraphStyle = paragraphStyles[p];
oldFont = paragraphStyle.appliedFont;
 
if (!set.onlyMissingFonts || (set.onlyMissingFonts && oldFont.status != FontStatus.INSTALLED)) {
newFont = FindFont(oldFont.name, fontList);
if (newFont != null) {
paragraphStyle.appliedFont = newFont;
countParStyles++;
}
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ProcessCharStyles() {
var characterStyle, oldFontFamilyName, oldFontStyle, oldFont, newFont,
characterStyles = doc.allCharacterStyles;
 
if (calledFromBatchProcessor) {
g.WriteToFile("\nProcessing character styles");
}
else {
progressTxt.text = "Processing character styles";
progressBar.minvalue = 0;
progressBar.maxvalue = characterStyles.length;
}
 
for (var c = 1; c < characterStyles.length; c++) {
if (!calledFromBatchProcessor) progressBar.value = c;
characterStyle = characterStyles[c];
oldFontFamilyName = characterStyle.appliedFont;
oldFontStyle = characterStyle.fontStyle;
 
if (set.onlyMissingFonts) {
oldFont = FindDocFont(oldFontFamilyName, oldFontStyle);
if (oldFont != null) continue; // font installed -- skip it
}
 
newFont = FindFont(oldFontFamilyName + "\t" + oldFontStyle, fontList);
if (newFont != null) {
characterStyles[c].appliedFont = newFont;
countCharStyles++;
}
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function FindDocFont(fontFamilyName, fontStyle) {
var font;
var result = null;
var name = fontFamilyName.replace(/\s+$/,"").replace(/^\s+/,"") + ((fontStyle != NothingEnum.NOTHING) ? "\t" + fontStyle : "");
 
if (fontFamilyName != "") {
font = doc.fonts.itemByName(name);
 
if (font.isValid && font.status == FontStatus.INSTALLED) {
result = font;
}
}
 
return result;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ProcessFindChange() {
var oldFont, newFont, changed;
 
if (calledFromBatchProcessor) {
g.WriteToFile("\nProcessing find-change");
}
else {
progressTxt.text = "Processing find-change";
progressBar.minvalue = 0;
progressBar.maxvalue = fontList.length;
}
 
if (debugMode) { // for debugging
var blue = MakeColor("=== Blue ===", ColorSpace.RGB, ColorModel.process, [0, 0, 255]);
}
 
with (app.findChangeTextOptions) {
includeMasterPages = true;
includeHiddenLayers = true;
includeLockedLayersForFind = true;
includeLockedStoriesForFind = true;
includeFootnotes = true;
wholeWord = false;
caseSensitive = false;
}
 
for (var i = 0; i < fontList.length; i++) {
if (!calledFromBatchProcessor) progressBar.value = i + 1;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
oldFont = app.fonts.itemByName(fontList[i][0]);
 
if (!set.onlyMissingFonts || (set.onlyMissingFonts && oldFont.status != FontStatus.INSTALLED)) {
newFont = FindFont(fontList[i][0], fontList);
 
if (newFont != null) {
app.findTextPreferences.appliedFont = oldFont;
app.changeTextPreferences.appliedFont = newFont;
 
if (debugMode) { // for debugging
app.changeTextPreferences.fillColor = blue;
}
 
changed = doc.changeText();
 
countFC += changed.length;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.NOTHING;
}
}
} // end for
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ProcessTextStyleRanges() {
var tsr, oldFontName, oldFont, newFont,
countTsr = 0,
textStyleRanges = doc.stories.everyItem().textStyleRanges.everyItem().getElements();
 
if (calledFromBatchProcessor) {
g.WriteToFile("\nProcessing text style ranges");
}
else {
progressTxt.text = "Processing text style ranges";
progressBar.minvalue = 0;
progressBar.maxvalue = textStyleRanges.length;
}
 
if (debugMode) { // for debugging
var red = MakeColor("=== Red ===", ColorSpace.RGB, ColorModel.process, [255, 0, 0]);
var green = MakeColor("=== Green ===", ColorSpace.RGB, ColorModel.process, [0, 255, 0]);
}
 
while (tsr = textStyleRanges.shift()) {
countTsr++;
if (!calledFromBatchProcessor) progressBar.value = countTsr;
oldFont = tsr.appliedFont;
oldFontName = tsr.appliedFont.name;
 
if (!set.onlyMissingFonts || (set.onlyMissingFonts && oldFont.status != FontStatus.INSTALLED)) {
newFont = FindFont(oldFontName, fontList);
 
if (newFont != null) {
try {
tsr.appliedFont = newFont;
countTsrApplied++;
if (debugMode) tsr.fillColor = green; // for debugging
}
catch(err) {
if (calledFromBatchProcessor) {
g.WriteToFile("ERROR: " + err.message + ", line: " + err.line);
}
else if (debugMode) { // for debugging
tsr.fillColor = red;
}
}
}
}
} // end while
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function FindFont(oldFontName, list) {
var newFontName, newFont;
oldFontName = oldFontName.replace(/\s+$/,"").replace(/^\s+/,"");
 
for (var x in list) {
if (oldFontName == list[x][0]) {
newFontName = list[x][1];
newFont = app.fonts.itemByName(newFontName);
 
if (newFont.isValid && newFont.status == FontStatus.INSTALLED) {
return newFont;
}
}
}
 
return null;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ReadCsvData(csvFile) {
var line, temp, csvRecord, tempArr;
var csvData = [];
csvFile.open("r");
 
while (!csvFile.eof) { 
line = csvFile.readln();
if (line == "") continue; // skip empty lines
tempArr = line.split(";");
if (tempArr[0] == "" || tempArr[1] == "") continue; // skip if one element is empty
 
csvData.push([
eval("\"" + tempArr[0] + "\""), // A -- Find
eval("\"" + tempArr[1]+ "\"") // B -- Change to
]);
}
 
csvFile.close();
 
return csvData;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function GetCsv() {
var scriptFile = GetActiveScript();
var scriptFolderPath = decodeURI(scriptFile.path) + "/";
var csvFilePath = scriptFolderPath + csvFileName;
var csvFile = new File(csvFilePath);
 
if (csvFile.exists) {
return csvFile;
}
else {
return null;
}
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function GetActiveScript() {
    try {
        return app.activeScript;
    }
    catch(err) {
        return new File(err.fileName);
    }
}
//=======================================================================================
function GetTime() { // get exact time for the log -- hr : min : sec -- so we could know when exactly an error occured
var date = new Date();
var dateString = date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds();
return dateString;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function CalledFromBatchProcessor() { // Let's see if it's called as a 'secondary' (returns true) or as a 'regular' (returns false) script
var result = false;
 
try {
var arr = $.stack.split(/[\n]/);
if (arr.length > 0 && arr[0].match(/\[Batch processor/i) != null) {
result = true;
}
}
catch(err) {}
 
return result;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function NormalizeArgs(args) {
var line, temp, csvRecord, tempArr,
csvData = [];
 
for (var i = 0; i < args.length; i++) {
line = args[i];
if (line == "") continue; // skip empty lines
tempArr = line.split(";");
if (tempArr[0] == "" || tempArr[1] == "") continue; // skip if one element is empty
 
csvData.push([
eval("\"" + tempArr[0] + "\""), // A -- Find
eval("\"" + tempArr[1]+ "\"") // B -- Change to
]);
}
 
return csvData;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function PreCheck() {
if (app.documents.length == 0) ErrorExit("Please open a document and try again.", true);
doc = app.activeDocument;
if (doc.converted) ErrorExit("The current document has been modified by being converted from older version of InDesign. Please save the document and try again.", true);
if (!doc.saved) ErrorExit("The current document has not been saved since it was created. Please save the document and try again.", true);
 
if (GetCsv() == null) ErrorExit("The CSV file '" + csvFileName + "' is missing. It should be located in the same folder as this script.", true);
 
Main();
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function ErrorExit(error, icon) { // Something went totally wrong.
alert(error, scriptName, icon); // Give a warning
exit(); // and stop the script
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function CharCodeString(str) { // for debugging only
if (str.constructor.name == "Enumerator") return null;
 
var s = "";
 
for (var i = 0; i < str.length; i++) {
s += ((i != 0) ? "|" : "") + str.charCodeAt(i);
}
 
return s;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function MakeColor(colorName, colorSpace, colorModel, colorValue) { // for debugging only
var doc = app.activeDocument;
var color = doc.colors.item(colorName);
if (!color.isValid) {
color = doc.colors.add({name: colorName, space: colorSpace, model: colorModel, colorValue: colorValue});
}
return color;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function GetDuration(startTime, endTime) {
var str;
var duration = (endTime - startTime)/1000;
duration = Math.round(duration);
if (duration >= 60) {
var minutes = Math.floor(duration/60);
var seconds = duration - (minutes * 60);
str = minutes + ((minutes != 1) ? " minutes, " :  " minute, ") + seconds + ((seconds != 1) ? " seconds" : " second");
if (minutes >= 60) {
var hours = Math.floor(minutes/60);
minutes = minutes - (hours * 60);
str = hours + ((hours != 1) ? " hours, " : " hour, ") + minutes + ((minutes != 1) ? " minutes, " :  " minute, ") + seconds + ((seconds != 1) ? " seconds" : " second");
}
}
else {
str = duration + ((duration != 1) ? " seconds" : " second");
}
 
return str;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------
function GetDialogSettings() {
set = eval(app.extractLabel("Kas_" + scriptName));
if (set == undefined) {
set = {
parStyles: true,
charStyles: true,
findChange: true,
textStyleRanges: true,
onlyMissingFonts: false
};
}
 
return set;
}
//--------------------------------------------------------------------------------------------------------------------------------------------------------

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 Expert ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

I can see that manually changing those fonts isn't really an option. Two suggestions. The best solution would be to get the font that your customer uses. It's likely that their font, though it may have the ame name, has a different version number. InDesign is really as finicky as that. Secondly, if you can't get that font, ask Kasyan to add to his script a line so that a paragraph style's font is changed only if it matches a defined font. It's just a small addition.

 

All that said, Kasyan'r script doesn't work for me: it goes through the document, changes the font, but without effect. I had/have the same problem with a script similar to Kasyan's that I did a while ago (https://creativepro.com/files/kahrel/indesign/substitute_fonts.html).

 

Anyway, get in touch with Kasyan and see what he can do for 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
Explorer ,
May 20, 2023 May 20, 2023

Copy link to clipboard

Copied

LATEST

Thanks Peter 😃

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