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

Script for changing font

New Here ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

Hello, I am creating .Jsx script  to create automatic text, but i wanted to change font of that Text but i dont know how to do it.

can anyone help with this?

 

TOPICS
Scripting

Views

4.0K

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 1 Correct answer

Community Expert , Mar 16, 2020 Mar 16, 2020

One way to do is just set the font of the content of the textframe and the other way would be to apply a paragraph style to the content of the frame. The paragraph style can be reffered by name, use one of the following

myTextFrame.parentStory.appliedFont = "Arial" //Change with the name of the font you want

Apply paragraph style

myTextFrame.parentStory.appliedParagraphStyle = myDocument.paragraphStyles.itemByName("NameOfParagraphStyle") //Substitute with the name of the paragraph style you want
...

Votes

Translate

Translate
Community Expert ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

Hi,

 

Share what code you have written so far, the code would depend upon the what references you have in your code. For ex:- if you have to change the font of the text selection on the document, or of all the text in a selection of textframe, or find some pattern of text and change its font etc. Looking at your code we will be able to guide on what will best suit the workflow you are designing so that you learn as well

 

-Manan

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
New Here ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

Hello Manan,

Thanks for reply,

I write below code to create auto text, but the font of text is as per deafault setting but i have to change its font and size  through scripting. could you help me in that what should i do for that

var myDocument = app.documents.add();
var myTextFrame = myDocument.pages.item(0).textFrames.add();
myTextFrame.geometricBounds = ["12p", "40p", "10p", "10p"];
myTextFrame.contents = "®/™ ©2020 . All rights reserved. Used under license in Canada.";

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
Advisor ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

Hello  Patilg5!

 

you can try....

      myTextFrame = myTextFrame.parentStory.characters.everyItem();
      myTextFrame.appliedFont = app.fonts.item("Arial");
      myTextFrame.fontStyle = "Bold";

Regards,

Mike

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 ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

One way to do is just set the font of the content of the textframe and the other way would be to apply a paragraph style to the content of the frame. The paragraph style can be reffered by name, use one of the following

myTextFrame.parentStory.appliedFont = "Arial" //Change with the name of the font you want

Apply paragraph style

myTextFrame.parentStory.appliedParagraphStyle = myDocument.paragraphStyles.itemByName("NameOfParagraphStyle") //Substitute with the name of the paragraph style you want to use

 

The other properties you can use on the story object can be seen from the following link

https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Story.html#d1e530047

 

-Manan

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
New Here ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

Hello Manan,

Really appriciate your support,

Could you please tell me if I want to change font style and font size what will be script for same

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 ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

That would be the pointSize and fontStyle property, example below

myTextFrame.parentStory.fontStyle = "Italic"
myTextFrame.parentStory.pointSize = 15

You can find all these properties in the link i shared. Also if you use the paragraphstyle method i mentioned you will not have to do all this in code, make all these changes in the style and it will work no need to change the code everytime

 

-Manan

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
New Here ,
Mar 16, 2020 Mar 16, 2020

Copy link to clipboard

Copied

Many thanks Manan for helping me.

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

Copy link to clipboard

Copied

LATEST

Hi patilg5,

just to give you a variant of what Manan said.

There are ways to format text in the moment you are creating that text frame.

 

Just a sample below:

 

var page = app.documents[0].pages[0];

var newTextFrame =
page.textFrames.add
(
	{
		geometricBounds : ["12p", "40p", "10p", "10p"] ,
		contents : "®/™ ©2020. All rights reserved. Used under license in Canada." ,
		
		parentStory : 
		{
			appliedFont : "Arial" ,
			fontStyle : "Bold" ,
			pointSize : 15
		} ,
	
		textFramePreferences :
		{
			autoSizingType : AutoSizingTypeEnum.HEIGHT_ONLY ,
			autoSizingReferencePoint : AutoSizingReferenceEnum.TOP_CENTER_POINT ,
			verticalJustification : VerticalJustification.TOP_ALIGN
		}

	}
);

 

Regards,
Uwe Laubender

( ACP )

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