2 Replies Latest reply on Oct 28, 2010 1:35 PM by Haakenlid

    fitting text to text box

    talltim1 Level 1

      Is there a script that will go through a folder of indesign files and find any text frames that have overset text and reduce the text within those frames the minimum amount in pt size so the text will fit?

       

      Regards, Tim

        • 1. Re: fitting text to text box
          Haakenlid Level 3

          It's not very complicated to make such a script.

          But you might end up with some very ugly looking documents with tiny, unreadable type.

          Should leading also be shrunk?

          What about text that is aligned to the baseline grid?

          • 2. Re: fitting text to text box
            Haakenlid Level 3

            You can try this.

            But be sure to backup your files first, since the script will save the files. And I haven't really tested it properly.

            The script will throw an error if the font size gets too small. Be default I've set the minimum size to 2.

             

            The first few lines I took from the script tomaxxi made for you earlier:

             

            var myFolder = Folder.selectDialog("Please select a folder containing the InDesign files.");
            myFolderContents = myFolder.getFiles("*.indd");
            myFileAmount = (myFolderContents.length - 1);
            for (i = myFileAmount; i >= 0; i--) {
                app.open(File(myFolderContents[i]));
                shrinkToFit();
                app.activeDocument.close(SaveOptions.YES);
            }
            
            function shrinkToFit(){
                var myDoc = app.activeDocument;
                var myStory;
                var myRange;
                var minimumSize = 2; // will throw an error if the text is smaller than this minimum;
                var shrinkFactor = 0.9; // how much the text should be reduced each time.
                for (n=0; n<myDoc.stories.length; n++){
                    myStory = myDoc.stories[n];
                    try{
                        while(myStory.overflows){
                            for (i=0; i<myStory.textStyleRanges.length; i++){
                                myRange = myStory.textStyleRanges[i];
                                myRange.pointSize=myRange.pointSize*shrinkFactor;
                                if (myRange.pointSize<minimumSize){
                                    throw ("The text is getting too small, but it's still overflowing");            
                                }
                            }
                        }
                    } catch(error){
                        alert("YOU'VE GONE TOO FAR!!!!\r"+error);
                    }
                }
            }