Skip to Content

Reduce font size automatically in a multiline textfield

Oct 11, 2017 at 01:22 PM


avatar image


i am using a multi line textfield with dynamic text.

I need to reduce the font size automatically when there are too many lines that the text would be cut off.

i know JS code thats counts the characters and reduces the font size if needed:

var len;
len = this.rawValue.length;
if (len>40){
this.font.size = „20pt“;
} else {
this.font.size = „10pt“;

But this will not fix my problem due i have to recuce the font not after x charcters but after x lines. Do you have an idea how to count the lines to recudce the font size?

Another idea: In an adobe forum i found the answer "just set font size for this field to 0 and it will determine the correct size automaticaly". But unfortunately i am not able to set the text size to 0.


10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Roberto Vacca Oct 16, 2017 at 07:44 AM


to set font size to 0 you need to use a text-field and try to use last version of livecycle designer; as you can see in the forn palette on the top-left-right, I set 0 as font size.

But that's not the only thing you need to do. To get your automation you'll need to put an 'X' in DYNAMIC option of your sfpdocparams structure, or you'll see nothing.

By the way, if you want to find lines number, you'll need to do a calculation, but this is only an estimation:

var txlen = this.rawValue.length;

var boxwidth = 12; // cm

var boxheight = 16; // cm

var nlines = Math.sqrt( boxheight / ( txlen / boxwidth ) );

I'm struggling too with "auto-size", but it seems there's no a well-known solution.

Have a try, and let me know if you solve it.

10 |10000 characters needed characters left characters exceeded