Expand my Community achievements bar.

Guidelines for the Responsible Use of Generative AI in the Experience Cloud Community.
SOLVED

Shrink-to-fit text default font size

Avatar

Level 2

Hi folks -

I'm looking for some help with the shrink-to-fit functionality. Is there a method to set the default starting font to something other than size 12 for the shrink-to-fit function?

1 Accepted Solution

Avatar

Correct answer by
Level 6

Use a multi-line text field (allowing Multiple lines) and set the field value to "0". You wont be able to control the starting font size, but the text will shrink when it reaches the end of the field (similar to AcroForms when the font size is set to Auto).

Note: I believe this requires saving as a Dynamic form vs Static.

View solution in original post

13 Replies

Avatar

Correct answer by
Level 6

Use a multi-line text field (allowing Multiple lines) and set the field value to "0". You wont be able to control the starting font size, but the text will shrink when it reaches the end of the field (similar to AcroForms when the font size is set to Auto).

Note: I believe this requires saving as a Dynamic form vs Static.

Avatar

Level 2

Thanks for the posts but no one has answered the question conclusively yet.

Avatar

Level 6

The solution I provided above works. I've used it several times.

Avatar

Level 2

I also stumbled into the "allow multiple line" as a partial fix. While checking that option does not let you control the starting font size, it does shrink the starting font size a bit making the font look more appropriate with forms designed in the 10-11 font size range.

Avatar

Level 2

Guys,

I think you all (except radzmar) didn't caught the point. He don't want to know, how the "auto-text-size" works. That's what he knows.

He want to know, wether there is any possiblity to change the default font size, before LCD starts to shrink.

Example: You want to have similar pages with the same font size (e.g. 8pt -> not 12pt as it is), but if any page's space isn't sufficient, he wants to auto-shrink the text until it fits.

The easy answer would be no, as radzmar said before.

I'm looking for that function for more than a half year now, without any solution. I think there might be a chance, to write a special JavaScript or XML code into your formular, to do that. But I really don't know, how that should look like. Maybe a JavaScript for the "exit" which checks, wether your space isn't sufficient and than switches over to "auto-shrink".

I could envision that there is some piece of code, which does that. But I'm really now JavaScript writer :-D

And there are just a handfull of people who knows how to write a good JavaScript within LCD.

Kindly regards,

Florian

Avatar

Level 3

I've been looking for a good answer for this aswell.

And as Radzmar answered, from what I have found it seem that the answer to your question is "No, any such method does not exist".

Personally I tried to work around it by having a check on the change event and if the text field overflows I would lower the font etc. However, the font size of the field doesn't update "immediately"/dynamically when changing the font for the field but rather it updated when the field was exited (even though some effort to force a layout update etc. and the scripting/change of font taking place on the change event). My final solution ended up being something similar to what Florian described above.

(on change event)

if(xfa.event.newText.length == 24){

    this.font.size = "0pt";

}

This was for a field with the standard font size of 10pt from the start, and the 24 character limit I just found as an estimate of the number of characters that would fill up the text field. So now it would keep the font that I want until it overflows, in that case the user just keeps writing and after that the font size is shrunk to make the text fit.

I'd like to believe there is a better way to do it, however this is at least something that works.

Avatar

Level 2

Hi mattiaswallin,

great piece of code for that! I worked with the length-event in case of an overflow. But this is cool. Only thing is the problem with differing fonts. But I think RTF and "auto size" are mutually exclusive right? So there is no problem at all.

Great code! Will use that too, if you permit ;-)

Kindly regards,

Florian

Avatar

Level 2

Flrorian - I get what Radzmar said. What I'm trying to convey here is that if you set the box to allow multiple lines, as both I and SI_MSD7 said, it will shrink the text slightly to give you a smaller starting text size.

Avatar

Level 2

As far as I know, AwesomeNick, multilining does not give control about the text size before shrinking. Just gives any standard size (12 I think?) but not the option to set a size and after that doesn't fit, shrink.

Kindly regards,

Florian

Avatar

Level 2

It would appear you have missed the point. Before this gets out of hand let me clarify: multi-lining does NOT give you control over the starting font. What it DOES do is shrink the starting text slightly. This may or may not work depending on what you're looking for. For my purposes, and at least one other person uses this workaround, it is sufficient.

To drive the point home, one of the forms I am working on has a field text that is roughly 4.8 inches wide. With the font set to auto-shrink for that field, and the font type set to Arial, I can fit 23 lower case w's. If I check the "allow multiple lines" option I am able to enter 28 w's in the same field with those exact same field settings before the text begins to shrink-to-fit.

Avatar

Level 3

Yes, using multi line makes the starting font size of an auto fitted text field a bit smaller. And in a sense that is a method to set the default starting font to something other than the regular (even though it does not give you control).

So as you actually wrote initially as a reply to that answer, it's not a conclusive answer (nor solution) but at least it's sort of a pain relief. It is better than basic function, but not perfect.

Great if it works for you!

Avatar

Level 1

Hi,

 

I know this is years too late, but could help someone. I developed this javascript for Acrobat Pro. I found someone that had a version of it and build on it a bit more.

 

Place this in the event custom calculation. It is a bit iffy is you try to use it with rich text, but fine for multi and single line and scrolling text.

 

What happens is it will set the font to auto originally so any length can be typed in and it will shrink if needed. You can then set a character limit for size 12 to be applied when you exit the field. it in a way will set your default to 12, just based on character length. You will see it applied when you exit the field.

 

The easiest way to work out the length is by setting the field you want to size 12 and filling it. do a character count and apply that to the code.

 

var field = event.target.value.toString().length;

if ( field == 0   // when field is empty set text size to auto
     ||          // OR
     field > 20) // when field has less than a character length (eg 20)
{
    event.target.textSize = 0;   // text size set to auto
}else{
    event.target.textSize = 12;  // text size wanted. (eg 12)
}

 

Hope this can help.