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

Auto change text size to size of text box?

Community Beginner ,
Nov 12, 2021 Nov 12, 2021

Copy link to clipboard

Copied

Hi,

Is there a way to make text automatically change size to the size of a text box?

So no matter how much text is entered, it never falls out of the box.

Thanks,

Em

TOPICS
Scripting , Type

Views

15.7K

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 2 Correct answers

Community Expert , Nov 12, 2021 Nov 12, 2021

No, you are not doing something wrong, it was me misunderstanding.

There is no standard option in Illustrator to do this.

Maybe a script?

Votes

Translate

Translate
Engaged , Nov 18, 2021 Nov 18, 2021

Touch-wood this should resize text larger/smaller to fit the frame. Caveat emptor, E&OE, etc. If OP requires a more complex script they are welcome to DM me.

 

 

 

 

// fit_text_to_frame.jsx

// resizes text larger/smaller to fit the selected text frame(s)
// (the text frame must be fully selected; point text and non-text items are ignored)
// current limitations: this assumes all characters are same size; leading is not adjusted

(function() {

var MIN_SIZE = 1, MAX_SIZE = 1296 // practical limits, 
...

Votes

Translate

Translate
Adobe
Community Beginner ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Thank you, I'm new here and (I guess obviously) not good at the search function. Do you know if there are any threads about this issue for Acrobat? 

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 ,
Nov 20, 2021 Nov 20, 2021

Copy link to clipboard

Copied

That's a very good approach, hhas01. Thank you.

 

I did some tests and observed that for some reason it is sometimes required to execute the script two times in order to get it to work properly.

 

Haven't found a definitive cause that may explain why it happens. But it happens.

 

Perhaps next week I may be able to set up a sample file that contains type objects that do obey the script only when executing it two times.

 

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
Engaged ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

I have run some general experiments and noticed a bizarre behavior in Illustrator (25.2.2, 25.3.1, 26.0.1):

 

Create a new document and add a text frame containing text set in 6pt Myriad Pro Regular. Then run the following script:

var textFrame = app.activeDocument.textFrames[0]
textFrame.textRange.characterAttributes.size = 12
alert(textFrame.textRange.characterAttributes.size)

or:

tell application "Adobe Illustrator"
	tell document 1
		set (size of text range of text frame 1) to 12
		get (size of text range of text frame 1)
	end tell
end tell

The text fails to change size and remains at 6pt. Manually set the text to, say, 17.5pt and run the script: it fails to change size again.

 

Try it with a different font style or family, it works. Modify the script to set it to 11.5pt or 14pt, it works.

 

Run the same test in Illustrator 16.0.0 (CS6), it works.

 

If others would like to test and confirm, I would appreciate it.

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
Advocate ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

Pour moi

Myriad Pro Regular. ne fonctionne pas sur CS6 16.0.0 64Bits

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 ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

It's indeed bizarre. I can confirm it.

 

Even more bizarre is that it just sometimes works with other fonts (I tried Minion Pro, Acumin Variable Concept, Bahnschrift and some others). If I try it repeatedly, it may or may not work for no obvious reason. It's kind of a random behaviour.

 

Tested with Illustrator 26.0.1 on Mac OS 12.0.1.

 

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
Engaged ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

If you have other test .ai files that show incorrect behavior with the [corrected] fit_text_to_frame.py script above, please DM me. It’s possible my code has additional bugs/omissions in addition to the two I already patched above, in which case I can run your files here and hopefully reproduce and diagnose the problem.

 

 

The 12pt Myriad Pro Regular problem I mention because that one appears to be a bug in AI’s scripting implementation. (That AI itself defaults to 12pt Myriad Pro Regular for newly created text frames might not be unrelated. At any rate it smells.) I wasn’t even aware of it until I happened to run the fitting script using a 6pt Myriad Pro Regular text frame as starting point. After which it took me a while to narrow down the exact cause, because the observed behavior defied immediate explanation. (It was only by performing each “resize” instruction one at a time and visually confirming the result, I noticed that on one very particular step, 6pt → 6pt×2, the text size wasn’t increasing as it should. After which I stripped down to the test cases above, confirming it wasn’t my bug. Had I not happened to use that particular font and a factor/multiple of 12 in one of my test .ai files, I’d still be searching now.)

 

This is looking to be a general problem in AI’s scripting API, e.g. the following also fails to work correctly on Myriad Pro Regular text:

tell application "Adobe Illustrator"
	tell text frame 1 of document 1
		set size of paragraph 1 to 4 -- works
		redraw
		delay 0.3
		set size of paragraph 1 to 8 -- works
		redraw
		delay 0.3
		set size of paragraph 1 to 12 -- fails
		redraw
		size of character 1 -- returns 8.0 but should be 12.0!
	end tell
end tell

 

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 ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

Some further testing turns out that the Myriad issue somehow has something to do with the settings applied to the [Normal Character Style] in the Character Styles palette.

 

Changing it to a different font family seems to cure Myriad and contaminate the new standard font at the same time.

 

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
Engaged ,
Nov 25, 2021 Nov 25, 2021

Copy link to clipboard

Copied

Thanks. It’s possible that somewhere deep in the Illustrator source code there is something like the following (pseudocode) speed optimization:

if (new style != current style) { apply the new style } // else do nothing

except instead of “current style” (i.e. the style that’s currently applied to the text) someone put “default style” (i.e. the [Normal Character Style]) instead. Although that’s just an educated guess based on observation, and I’m sure there are other possible bugs that could manifest this faulty behavior.

 

There are multiple ways in which text can be styled (Character palette, Paragraph palette, Character Styles, Paragraph Styles, Appearances, scripting API, plugin API; any others?) and that all these competing sources of style information have to be merged into one before it can be applied to the text itself. Complex code (especially when it’s progressively added to over the years by different hands; e.g. to implement Appearances) could easily introduce/hide subtle logic errors.

 

I will write a bug ticket over the weekend and post a link to that for future reference once it’s submitted.

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 ,
Nov 21, 2021 Nov 21, 2021

Copy link to clipboard

Copied

hhas,

 

having to sometimes execute the fit_text_to_frame script two times apparently is related to the [Normal Character Style] issue as well. As far as I can see it can definitely be reproduced.

 

  1. Open a new document.
  2. Create an area type object and insert some placeholder text (by default its attributes are based on the settings in the [Normal Character Style] item in the Character Styles palette, usually it is Myriad Pro Regular, 12 pt, but it could be any other font and font size in case you modified this [Normal Character Style]).
  3. Reduce the horizontal or vertical size of the type object, so you get a good portion of overset text.
  4. Make sure that the font is still set to the default Myriad Pro Regular, 12 pt.
  5. Duplicate the type object and change the font size to 12,01 pt.
  6. Select the duplicate (12,01 pt) and run the fit_text_to_frame script. It works fine.
  7. Select the original type object (12 pt) and run the fit_text_to_frame script. It doesn't work as expected. Instead it decreases the font size to 11,906 pt.
  8. Select the original type object again and run the fit_text_to_frame script for the second time. Now it works as expected.

 

Guess you can confirm that behaviour?

 

The culprit is not Myriad Pro Regular. The [Normal Character Style] is the rascal.

 

One would have to do some further testing with other custom character/paragraph styles.

 

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
Advocate ,
Nov 23, 2021 Nov 23, 2021

Copy link to clipboard

Copied

Kurt,

Tu viens de découvrir ce que j'ai signalé à la page 1 de ce sujet,

je n'avais pas précise le nom de la police "Myriad Pro Regular",

pour [Normal Character Style] c'est probablement la raison du problème.

René

 

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 ,
May 19, 2023 May 19, 2023

Copy link to clipboard

Copied

LATEST

Can this be applied to an automated action to apply to all the text boxes set on variables? If yes, could you explain to me how?

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