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

Script for changing font

New Here ,
Mar 16, 2020 Mar 16, 2020

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
5.0K
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

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
...
Translate
Community Expert ,
Mar 16, 2020 Mar 16, 2020

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

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

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.";

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

Hello  Patilg5!

 

you can try....

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

Regards,

Mike

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

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

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

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
New Here ,
Jul 21, 2024 Jul 21, 2024

How can I do the same but on my computer Adobe PDF App (and not online)?
My font suddenly changes on my Adobe PDF to cursive font, and I cannot revert it to the original print font.
Would appreciate your guidance

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 Expert ,
Jul 21, 2024 Jul 21, 2024
quote

How can I do the same but on my computer Adobe PDF App (and not online)?
My font suddenly changes on my Adobe PDF to cursive font, and I cannot revert it to the original print font.
Would appreciate your guidance


By @Galit38712909x7cv

 

Are you exporting PDF from InDesign? 

 

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 Expert ,
Jul 21, 2024 Jul 21, 2024
LATEST
quote

 

Are you exporting PDF from InDesign? 

By @Robert at ID-Tasker

 

Probably not, as it's probably the same question OP posted here:

https://community.adobe.com/t5/acrobat-discussions/changing-font-when-writing-comments-on-pdf/m-p/14...

 

I guess she searched the forums further for something like "how to change font" and landed here.

 

@Galit38712909x7cv :

If my assumption is correct and you're not exporting your PDF from InDesign, then this is an InDesign forum for InDesign-specific discussions. Just make sure to search - and post to - the Acrobat forum itself, not the entire Adobe community. The search function on the forums can, admittedly, be confusing.

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

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

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

Many thanks Manan for helping me.

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

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 )

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