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
No, you are not doing something wrong, it was me misunderstanding.
There is no standard option in Illustrator to do this.
Maybe a script?
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,
...
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?
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.
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.
Copy link to clipboard
Copied
Pour moi
Myriad Pro Regular. ne fonctionne pas sur CS6 16.0.0 64Bits
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.
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
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.
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.
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.
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.
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é
Copy link to clipboard
Copied
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?