Copy link to clipboard
Copied
Hey all!
I've a doc full of diffranet textframes, and i want to change the font type for a scpicif textframe, how to do it?
I've used this code, it's good and works but change all the text frames, and i want to change only a spicifed frame!
The code
app.findTextPreferences=app.changeTextPreferences= NothingEnum.nothing;
app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
app.findTextPreferences.appliedFont = app.fonts.item("Times New Roman MT Std Bold");////Here you can specify your old font name
app.changeTextPreferences.appliedFont = app.fonts.item("Times New Roman Italic");////Here you can specify your NEW font name
doc.changeText();
and lets say that the frame i want to change
var rect2 = doc.pages[0].textFrames.add({
geometricBounds: [12.7, 12.7, 90, 90]
});
rect2.contents = "wooow"
and thanks all!
2 Correct answers
What is the font that you are using? Is it installed on the system or document fonts folder?
Try changing the code to the following
rect.texts[0].appliedFont = "Times New Roman"
rect.texts[0].fontStyle = "Bold"
-Manan
—once i type the name in the code
The name string has to be exact including any whitespace characters, so maybe try this variation on Manan’s suggestion and copy and paste the text from the alert dialog rather than typing the name—appliedFont is the family and style usually separated by a tab
//note that I’m getting the appliedFont.name and not appliedFont.fontFamily
alert(app.selection[0].texts[0].appliedFont.name)
//the appliedFont is the font name and style with a tab separating the
...
Copy link to clipboard
Copied
If you have the reference of the text frame you don't need to use the find change, just change the font like the following
rect.texts[0].appliedFont = app.fonts.item("Times New Roman MT Std Bold")
-Manan
Copy link to clipboard
Copied
The font i use is installed, so when i use the code that i've posted it works and change the font, but when id ur code and write the family font, it alerrt me that the requested font family is unaviliable.
Copy link to clipboard
Copied
Hello,
You can give this a try.
var rect2 = doc.pages[0].textFrames.add({
geometricBounds: [12.7, 12.7, 90, 90]
});
rect2.contents = "wooow"
rect2 = myYTextFrame.parentStory.characters.everyItem();
rect2.appliedFont = app.fonts.item("Helvetica Neue");
rect2.fontStyle = "Medium";
Regards,
Mike
Copy link to clipboard
Copied
There is error (
myYTextFrame
is undefined)
Copy link to clipboard
Copied
Sorry....
var rect2 = doc.pages[0].textFrames.add({
geometricBounds: [12.7, 12.7, 90, 90]
});
rect2.contents = "wooow"
myTextObject = rect2.parentStory.characters.everyItem();
myTextObject.appliedFont = app.fonts.item("Helvetica Neue");
myTextObject.fontStyle = "Medium";
Regards,
Mike
Copy link to clipboard
Copied
It works, but only with the bulit in fonts (i,e)
Times New Roman
Copy link to clipboard
Copied
Try something like the following
rect.texts[0].appliedFont = app.fonts.item("Times New Roman")
rect.texts[0].fontStyle = "Bold"
-Manan
Copy link to clipboard
Copied
It works, but i think because
Times New Roman
is a built-in font type. When i use mine, the installed one, it alert me that the requested font are unavaible. The weird thing when i replac the font from the UI not the script it wokrs!
Copy link to clipboard
Copied
Apply your font using the UI, select the frame and run the following code
alert(app.selection[0].texts[0].appliedFont.fontFamily)
This should give you the name of the font family that is to be used in the code I gave previously.
-Manan
Copy link to clipboard
Copied
indeed yes it gave me the name, and once i type the name in the code and specify the style, it alerts me that the requested font un available
Copy link to clipboard
Copied
What is the font that you are using? Is it installed on the system or document fonts folder?
Try changing the code to the following
rect.texts[0].appliedFont = "Times New Roman"
rect.texts[0].fontStyle = "Bold"
-Manan
Copy link to clipboard
Copied
I'm using a special font for my company, and yes it's installed in the system. still same issue. the furstrating thing that i can change the font and found the font family from the UI !
Copy link to clipboard
Copied
Can you share\post the "special font" for testing?
Regards,
Mike
Copy link to clipboard
Copied
it's for my company, but it works now. apperntly there was a tab space i didn't recognize it.
Copy link to clipboard
Copied
—once i type the name in the code
The name string has to be exact including any whitespace characters, so maybe try this variation on Manan’s suggestion and copy and paste the text from the alert dialog rather than typing the name—appliedFont is the family and style usually separated by a tab
//note that I’m getting the appliedFont.name and not appliedFont.fontFamily
alert(app.selection[0].texts[0].appliedFont.name)
//the appliedFont is the font name and style with a tab separating the name and style so try copying from the alert
app.selection[0].texts[0].appliedFont = "Myriad Pro Regular"
Copy link to clipboard
Copied
THANKS rob!!! it works perfictly! i didn't now about the tab! THANKS A LOT

