Copy link to clipboard
Copied
Hi,
I would like to use javascript to "Fit content to frame" to ALL TextFrame".
Any one can HELP!
Thx!
Copy link to clipboard
Copied
"Fit content to frame" is not an option for text frames.
Copy link to clipboard
Copied
how can I fit content to frame on my document?
Copy link to clipboard
Copied
app.activeDocument.rectangles.everyItem().fit(FitOptions.CONTENT_TO_FRAME);
Note the use of 'rectangles' -- this only works on images, not on text frames.
If you really really want a 'fit to content' for text frames, you will have to use something like
Copy link to clipboard
Copied
hi, thanks, If I have some textframe, how can I define there bounding box.
Copy link to clipboard
Copied
How would you set the code you supplied to Fit Content To Frame using the largest dimension (i.e. when the vertical and horizontal scales are not even (predominantly encountered after fitting the image to the frame))?
The below video demonstrates manually what I’m looking for in a script to accomplish (paying special attention to the copy+pasting of the largest number in the scale field in order to even out the scaling).
Thanks in advance.
Copy link to clipboard
Copied
This might not be what you are looking for but you can programmatically increase/decrease the point size of the font of a text frames as such (below are just sample scripts/examples of one text frame on a one page document):
//To increase font size until it fits without overflowing outside the text frame bounds
var doc = app.activeDocument;
var txf = doc.pages.item(0).textFrames.item(0);
while(!txf.overflows) {
var currentPointSize = txf.paragraphs.firstItem().pointSize;
txf.paragraphs.everyItem().pointSize = currentPointSize+1;
}
//To decrease font size until it fits without overflowing outside the text frame bounds
var doc = app.activeDocument;
var txf = doc.pages.item(0).textFrames.item(0);
while(txf.overflows) {
var currentPointSize = txf.paragraphs.firstItem().pointSize;
txf.paragraphs.everyItem().pointSize = currentPointSize-1;
}
You could also Fit Frame to Content
var doc = app.activeDocument;
var txf = doc.pages.item(0).textFrames.item(0);
while(txf.overflows) {
txf.fit(FitOptions.FRAME_TO_CONTENT);
}
Alternatively, you could outline the text and make it compound path and place it into a text frame and then do Fit Content to Frame, but that is going to give you stretched and most likely than not unreadable text.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more