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

Script for shrinking overset text?

New Here ,
Feb 09, 2013 Feb 09, 2013

I use data merge to create labels for guests attending functions. Usually this is around 500-1000 labels at one time. I usually set my text frame on the template page for a large point and then shrink it horizontally (I do this to minimize the number of pages I have to manually edit for overset text). I still get some names where they are long hyphenated names that create overset text.

Is there a script available where it will recognize there is overset text and then shrink the text down either by decreasing the point size or adjusting the horizontal spread of the text (maybe making it 100% to 80%)?

TOPICS
Scripting
9.7K
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 ,
Feb 09, 2013 Feb 09, 2013

I think the answer was in an earlier post: http://forums.adobe.com/message/4763303

In short, it is one of two answers:

  1. If the desired result is to expand the frame, this can be accomplished in cs6 using Persistent text frame fitting options.
  2. If the desired result is to change the size of the text without any input, there's a trick with GREP styles that I wrote about on my blog, along with a download of a pdf/indd of how it was done. http://colecandoo.wordpress.com/2012/02/18/square-pegs-now-fit-into-round-holes/

colly

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
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 ,
Feb 09, 2013 Feb 09, 2013

I want to maintain the same frame size since I have First Name and Last Name on two lines and it's already stretched out to the edges of the workspace I have.

I did review that link before I posted. It didn't really work. Was hoping there was a script instead.

I am using CS5, FYI.

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 ,
Feb 09, 2013 Feb 09, 2013

OK, so the first solution is out not only due to the version of InDesign but also because the frame is to stay the same size.

The GREP solution should work. By "it didn't really work", can you elaborate? What appeared to foul up or not perform as expected?

Perhaps another solution is this: http://in-tools.com/article/scripts-blog/fun-with-text-fitting-in-indesign/

If the answer wasn't in my post, perhaps it might be on my blog at colecandoo!
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
Mentor ,
Feb 09, 2013 Feb 09, 2013

Hi,

You could try this:

#target indesign

myDoc = app.activeDocument;

var textArr = new Array(), mRes, myPit, count, done;

mFramesToMove = new Array();

myPit = myDoc.allPageItems;    // array with doc pageItems (masterpages and groups included)

for (var k = 0; k < myPit.length; k++)

    if (myPit.constructor.name == "TextFrame" && myPit.overflows )

    textArr.push(myPit);    // array with overset textFrames

count = textArr.length;

if (count) mRes = mDialog (count);

else {alert ("No overset texts found"); exit (); }

for (var i = 0; i < textArr.length; i++) {

    done = mShrink (textArr, mRes);

    if (!done[0] ) {

        alert (done[1] + "\rFill a dialog field with a number");

        exit; }

    }

    if (mFramesToMove.length) {

        if (myDoc.layers.item("Overset frames").isValid)

            mLayer = myDoc.layers.item("Overset frames");

        else

            mLayer = myDoc.layers.add({LocationOptions: LocationOptions.AT_BEGINNING, name: "Overset frames"});

        for (var i = 0; i < mFramesToMove.length; i++)

        mFramesToMove.itemLayer = mLayer;

        alert ("Some frames (" + mFramesToMove.length + ") stay overset\rTake a look at layer 'Overset Frames' ");

        }

    else alert (count + " frames overset fixed");

function mDialog (number) {// "What to do" dialog

    var w = new Window("dialog","What to do?", undefined, {closeButton: false});

    w.add ("statictext", undefined, "Number of overset texts found:  " + number.toString() );

    var myTop = w.add ("panel");

    myTop.alignment = "left";

    myTop.orientation = "row";

    var myCheckBx = myTop.add ("group");

    myCheckBx.orientation = "column";

    myCheckBx.alignChildren = "left";

    var Ch1 = myCheckBx.add("checkbox", undefined, "point size limit: ");

    var Ch2 = myCheckBx.add("checkbox", undefined, "hori scale limit: ");

    var myEditBx = myTop.add ("group");

    myEditBx.orientation = "column";

    var Ed1 = myEditBx.add("edittext", undefined, undefined);

    Ed1.enabled = false; Ed1.characters = 4;

    var Ed2 = myEditBx.add("edittext", undefined, undefined);

    Ed2.enabled = false; Ed2.characters = 4;

    Ch1.onClick = function () {

        if (Ch1.value) Ed1.enabled = true;

        else Ed1.enabled = false;}

    Ch2.onClick = function () {

        if (Ch2.value) Ed2.enabled = true;

        else Ed2.enabled = false;}

    var myStatBx = myTop.add ("group");

    myStatBx.orientation = "column";

    myStatBx.add("statictext", undefined, " pt");

    myStatBx.add("statictext", undefined, " %");

    var b = w.add ("group");

        b.add ("button", undefined, "OK", {name: "ok"});

        b.add ("button", undefined, "Anuluj", {name: "cancel"});

    if (w.show() == 1)

        return [Ch1.value, Ed1.text, Ch2.value, Ed2.text];

    else exit();

    }

function mShrink (textFr, ToDoArr) {    // input textFrame and array with mDialog result

    var pSizeLimAc, pSizeLim, pSizeCurr, pSizeDiff, pSizeStepN, pSizeStep,

        hScaleAc, hScaleLim, hScaleCurr, hScaleDiff, hScaleStepN, hScaleStep,

        ToDo;

    pSizeLimAc = ToDoArr[0];

    hScaleAc = ToDoArr[2];

    pSizeLim = ToDoArr[1];

    if (pSizeLimAc) {

        if (isNaN (parseFloat(pSizeLim) ) ) return [false, "point size is not a number"];

        else pSizeLim = parseFloat(pSizeLim);

        pSizeCurr = textFr.parentStory.pointSize;

        pSizeDiff = pSizeCurr - pSizeLim;

        pSizeStepN = pSizeDiff / 0.1;

        pSizeStep = 0.1;

        }

    hScaleLim = ToDoArr[3];

    if (hScaleAc) {

        if (isNaN (parseFloat(hScaleLim) ) ) return [false, "hori scale is not a number"];

        else hScaleLim = parseFloat(hScaleLim);

        hScaleCurr = textFr.parentStory.horizontalScale;

        hScaleDiff = hScaleCurr - hScaleLim;

        if (pSizeLimAc) hScaleStepN = pSizeStepN;

        else hScaleStepN = hScaleDiff;

        hScaleStep = Math.round(hScaleDiff/hScaleStepN*10)/10;

        }

    if (!(hScaleDiff > 0) ) hScaleAc = false;

    if (!(pSizeDiff > 0) ) pSizeLimAc = false;

    if (pSizeLimAc && hScaleAc) ToDo = 3;

    else if (pSizeLimAc) ToDo = 1;

        else if (hScaleAc) ToDo = 2;

            else ToDo = 0;

    switch (ToDo) {

        case 1: {

            while (pSizeStepN-- && textFr.overflows)

                textFr.parentStory.pointSize -= pSizeStep;

                break; }

        case 2: {

            while (hScaleStepN-- && textFr.overflows)

                textFr.parentStory.horizontalScale -= hScaleStep;

                break; }

        case 3: {

            while (hScaleStepN-- && textFr.overflows)

                {

                textFr.parentStory.pointSize -= pSizeStep;

                textFr.parentStory.horizontalScale -= hScaleStep;

                }

                break; }

        default: break;

        }

    if (textFr.overflows) mFramesToMove.push(textFr);

    return [true];

    }

User will be asked for pointSize and horizontalScale lower limit.

rgds

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 Beginner ,
Jun 26, 2014 Jun 26, 2014

OMG! You are a god among men sir! I create bulk labels in indesign and there are obvious size constraints. I just used this script and it sized 19 pages of over-set text with a click of a button and looks beautiful! You have just saved me soooooooo much time in my process of creating these labels.

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 ,
Jan 29, 2015 Jan 29, 2015

This is brilliant. Thank you.

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 ,
Oct 09, 2015 Oct 09, 2015

You are the best!

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 ,
Oct 28, 2015 Oct 28, 2015

wow this script is fantastic, but does anyone know how to make it horizontally scale the text by automatically applying just the amount of scaling which would make the text fit into the frame, in other words, without setting any limit and let the script decide which is the correct value ? I've got a very long document with hundreds of frames  that need scaling, each one with different values and I must not modify the frames in any way.

thank you!

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
People's Champ ,
Oct 28, 2015 Oct 28, 2015

You could check out our Fit Text to Frame: http://www.id-extras.com/products/fit-text-to-frame (free for 30 days).

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 ,
Aug 18, 2016 Aug 18, 2016

Hi this script is an incredible script, I work for a company that supplies name badges and almost 20% of the time the names are overset. My only enquiries are can the script be adjusted to not ask for a limit and simply kern until fit, and is there a way to make this work for multiple line text within the same frame. Thanks!

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
Explorer ,
Sep 25, 2018 Sep 25, 2018

Hi, would someone mind explaining how to actually create this script? I have copy and pasted it into Textedit, added the extension .jsx and put it in the appropriate scripts folder. When I double click it, it's coming up with an error - I'm no script expert but every day is a school day!

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
Explorer ,
Sep 25, 2018 Sep 25, 2018

Ah I figured it out - don't copy the numbers!

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 ,
Sep 25, 2018 Sep 25, 2018
LATEST

This is a real simple script that will loop through all the text frames of the document and if the text overflows (overset text) will reduce the point size of the font by 1 until it no longer oversets.

var doc = app.activeDocument;

for(var i = 0; i < doc.textFrames.length; i++) {

    while(doc.textFrames.item(i).overflows) {

        var fontSize = doc.textFrames.item(i).paragraphs.item(0).pointSize;

        doc.textFrames.item(i).paragraphs.item(0).pointSize = fontSize-1;

    }

}

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