Copy link to clipboard
Copied
Hi,
I need to change the font type of an InDesign document using InDesign script (javascript). I found some online references in InDesign scripting guide and running the following snippet, gives me errors.
//Clear any existing preferences
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
app.findChangeTextOptions.caseSensitive = false;
app.changeTextPreferences.appliedFont = app.fonts.item("DEVANAGARI MT");
app.documents.item(0).changeText();
Get the following msg from InDesign server.
Error code: 1
Error description: changeText
The indesign file used to change the font is definitely not corrupted, cause the following script to export the file as .png works just fine. Any help appreciated.
app.pngExportPreferences.exportResolution = 100.0;
app.documents.item(0).exportFile(ExportFormat.PNG_FORMAT, previewDocument);
Hi,
Try this 1-liner:
app.documents.item(0).stories.everyItem().appliedFont = app.fonts.item("DEVANAGARI MT");
Above assumes that specified font is available. Some troubles can start with font's name, cause not always WYSIWYG.
To be sure how to refer to specific font by its name - select some text and notice console in ESTK runing this:
app.selection[0].appliedFont.name
Jarek
Copy link to clipboard
Copied
Hi,
Try this 1-liner:
app.documents.item(0).stories.everyItem().appliedFont = app.fonts.item("DEVANAGARI MT");
Above assumes that specified font is available. Some troubles can start with font's name, cause not always WYSIWYG.
To be sure how to refer to specific font by its name - select some text and notice console in ESTK runing this:
app.selection[0].appliedFont.name
Jarek
Copy link to clipboard
Copied
Hi,
if you really want to use Find/Change, try this ...
var docFonts = app.activeDocument.fonts;
for(var i = docFonts.length - 1; i >= 0; i--){
app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedFont = docFonts;
app.changeTextPreferences.appliedFont = "DEVANAGARI MT";
app.activeDocument.changeText();
}
Copy link to clipboard
Copied
Hi Jarek,
Thanks for the quick reply. That worked!
@Ronald : I seem to understand your solution, but am still getting error at changeText(). Wish adobe gives more contextual information along with the error messages. Thanks for the help.
Error Code : 1
Error Description : changeText
Chinmay
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more