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

Apply "Fit content to frame" to all TextFrame - Javascript

New Here ,
Sep 18, 2009 Sep 18, 2009

Hi,

I would like to use javascript to "Fit content to frame" to ALL TextFrame".

Any one can HELP!

Thx!

TOPICS
Scripting
4.8K
Translate
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 ,
Sep 18, 2009 Sep 18, 2009

"Fit content to frame" is not an option for text frames.

Translate
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 ,
Sep 18, 2009 Sep 18, 2009

how can I fit content to frame on my document?

Translate
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 ,
Sep 18, 2009 Sep 18, 2009
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

  • note the original bounding box of a text frame
  • fit frame to content
  • scale frame to original bounding box.
Translate
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 ,
Nov 19, 2009 Nov 19, 2009

hi, thanks, If I have some textframe, how can I define there bounding box.

Translate
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
Guest
May 08, 2018 May 08, 2018

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.

Translate
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
Participant ,
May 09, 2018 May 09, 2018
LATEST

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.

Translate
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