Highlighted

Script for changing font

New Here ,
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?

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

581

Likes

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

Script for changing font

New Here ,
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?

 

Adobe Community Professional
Correct answer by Manan Joshi | Adobe Community Professional

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

TOPICS
Scripting

Views

582

Likes

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
Mar 16, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Mar 16, 2020 0
New Here ,
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.";

Likes

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
Reply
Loading...
Mar 16, 2020 0
Engaged ,
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

Likes

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
Reply
Loading...
Mar 16, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Mar 16, 2020 0
New Here ,
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

Likes

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
Reply
Loading...
Mar 16, 2020 0
Adobe Community Professional ,
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

Likes

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
Reply
Loading...
Mar 16, 2020 0
New Here ,
Mar 16, 2020

Copy link to clipboard

Copied

Many thanks Manan for helping me.

Likes

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
Reply
Loading...
Mar 16, 2020 0
Adobe Community Professional ,
Mar 17, 2020

Copy link to clipboard

Copied

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 )

Likes

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
Reply
Loading...
Mar 17, 2020 1