Skip to main content
Participant
February 22, 2021
Answered

Altering text size to fit width of text frame

  • February 22, 2021
  • 1 reply
  • 738 views

Hi,

When using a text box to house an article title my desired format is to change the size of the font for each line so that it fits the entire width of the text box but doesn't alter letter spacing. Is there an easy way to do this as I'm currently altering each line of text manually.

Thanks

This topic has been closed for replies.
Correct answer rob day

You might be able to script it, select the entire line and run this script:

 

var doc = app.documents.item(0);
var s = doc.selection;
var i = .1;

if (s[0] == null ||  s[0].lines.length>1) {
	alert("Please select a single line of text")
}else{
    var l = s[0].lines[0]
    while (s[0].lines.length==1) {
       l.pointSize = l.pointSize + i
    }
    l.pointSize = l.pointSize - i
}

 

 

1 reply

rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
February 22, 2021

You might be able to script it, select the entire line and run this script:

 

var doc = app.documents.item(0);
var s = doc.selection;
var i = .1;

if (s[0] == null ||  s[0].lines.length>1) {
	alert("Please select a single line of text")
}else{
    var l = s[0].lines[0]
    while (s[0].lines.length==1) {
       l.pointSize = l.pointSize + i
    }
    l.pointSize = l.pointSize - i
}

 

 

Niall5E7DAuthor
Participant
February 22, 2021

Hi Rob,

Thanks for this, it's a big help! It's almost there but it doesn't seem to like when I do it on a sinlge word on a line of it's own, I get the below error and the hgihlighted text disappears:

 

The other issue that highlights is that I can't then undo back to the position prior to running the script.

Thanks again for your help on this

 

rob day
Community Expert
Community Expert
February 22, 2021

Sorry, it would not work for a single word because the script is checking for the line to break and a single word or character wouldn’t necessarily break. Maybe someone else will have a better idea.