7 Replies Latest reply on Sep 3, 2015 4:16 AM by Eric Lipton Ice

    indesign text fit to frame

    abspeed

      I'm looking for a script that will allow me to fit some text into a frame rather than fitting a frame to the text.

       

      Can anyone help please?

       

      All the best,

        • 1. Re: indesign text fit to frame
          Ronald63 Level 4

          Hi Allan,

           

          I found this snippet in my archives. I hope this will help you.

          
          fitContentToFrame();
          
          function fitContentToFrame(){
          
              var allTextFrames = app.activeDocument.textFrames;
          
              for(var i=0;i<allTextFrames.length;i++){
                  var aTextFrame= allTextFrames[i];
                  var myParagraphStyle=aTextFrame.paragraphs[0].appliedParagraphStyle;
                  var myStory =aTextFrame.parentStory;
                  var myOver=aTextFrame.overflows;
                  var myPointSize= myParagraphStyle.pointSize; 
                  var myTrack= myParagraphStyle.tracking; 
                  var myHScale= myParagraphStyle.horizontalScale;
                  var myLead=myParagraphStyle.leading;
                  var myMaxLead = myPointSize * 1.5;
                  var myMinLead = myPointSize * 0.8;
                  var myMaxHScale = myHScale * 1.3;
                  var myMinHScale = myHScale * 0.7;
                  var myMaxTrack = myTrack + 50;
                  var myMinTrack = myTrack - 50;
                  var myTrackIncrement =1;
                  var myLeadIncrement = 0.01; 
                  var myHScaleIncrement = 0.25;
                  
                  if (myParagraphStyle.leading==Leading.auto) {
                      var myLead=myPointSize * 1.2;
                  }
          
                  while (myOver==false && myLead <= myMaxLead && myHScale<= myMaxHScale && myTrack <= myMaxTrack)
                      {
                      var myLead = myLead + myLeadIncrement;
                      var myHScale = myHScale + myHScaleIncrement;
                      var myTrack = myTrack + myTrackIncrement;
                      myStory.leading = myLead;
                      myStory.horizontalScale = myHScale;
                      myStory.tracking=myTrack;
                      var myOver=aTextFrame.overflows;
                      }
                  while (myOver==true && myLead >= myMinLead && myHScale >= myMinHScale && myTrack >= myMinTrack)
                      {
                      var myLead = myLead - myLeadIncrement;
                      var myHScale = myHScale - myHScaleIncrement;
                      var myTrack = myTrack - myTrackIncrement;
                      myStory.leading = myLead;
                      myStory.horizontalScale = myHScale;
                      myStory.tracking=myTrack;
                      var myOver=aTextFrame.overflows;
                      }  
              }
              
          }
          
          • 2. Re: indesign text fit to frame
            abspeed Level 1

            Hi Ronald.

             

            Thanks for this, but unfortunately i could not get the text fitting properly. The text sizes a little, but does not fill the frame.

             

            I am using Indesign CC 2014 - coudl this be part of the issue?

             

            Cheers

            • 3. Re: indesign text fit to frame
              Ronald63 Level 4

              Hi Allan,

               

              Try to increases max values
              
              
              
              
              
              
              
                  
              var myMaxLead = myPointSize * 1.5;
              
              
                  
              var myMaxHScale = myHScale * 1.3;
              
              
                  
              var myMaxTrack = myTrack + 50;
              
              
              
              
              
              
              
              
              • 5. Re: indesign text fit to frame
                abspeed Level 1

                Hi, yes i found this late last night, works quite well, but i need to find a way of getting the descenders inside the text frame.

                • 6. Re: indesign text fit to frame
                  TᴀW Adobe Community Professional & MVP

                  Hmm, well, InDesign always allows descenders to extend beyond the bottom of the text frame.

                   

                  What you could do, though, is simply set the bottom of the text frame to have, say, a 1 mm inset (this could be set as part of the object style). That should keep the descenders inside the bounds of the text frame. Does that work?

                  • 7. Re: indesign text fit to frame
                    Eric Lipton Ice

                    Hi,

                     

                    Is this what you want?

                    (make a textframe selection and then run the script)

                     

                    tell application "Adobe InDesign CS6"

                        activate

                        tell document 1

                            set xFrame to item 1 of selection

                            set {w, x, y, z} to geometric bounds of xFrame

                            set orgBreedte to (z - x)

                            set transform reference point of layout window 1 to top left anchor

                            set properties of xFrame to {text frame preferences:{auto sizing type:height and width proportionally, auto sizing reference point:top left point}}

                            set a to visible bounds of xFrame

                            set x1 to second item of a

                            set x2 to fourth item of a

                            set b to x2 - x1

                            set c to orgBreedte / b * 100

                            tell xFrame to set horizontal scale to c

                            tell xFrame to set vertical scale to c

                        end tell

                    end tell

                     

                    Grtz, EricLiptonIce