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

How to change font type using InDesign scripting (Javascript) ?

Community Beginner ,
Aug 04, 2015 Aug 04, 2015

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);

TOPICS
Scripting
2.3K
Translate
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 1 Correct answer

Mentor , Aug 04, 2015 Aug 04, 2015

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

Translate
Mentor ,
Aug 04, 2015 Aug 04, 2015

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

Translate
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
Enthusiast ,
Aug 04, 2015 Aug 04, 2015

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();

}

Translate
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 ,
Aug 04, 2015 Aug 04, 2015
LATEST

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

Translate
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