Expand my Community achievements bar.

Submissions are now open for the 2026 Adobe Experience Maker Awards.

Mark Solution

This conversation has been locked due to inactivity. Please create a new post.

Automatic font size reduction in a PDF form

Avatar

Former Community Member

Hello everybody!

I'm working with SAP.

On my current project I would like to implement a customer form via Adobe Lifecycle Designer.

I'm going to ask a developer to implement the following logic:

There is a fixed rectangular area in the form. This area should represent a text.

In case of long text I would like to reduce the font size to fit the text into the area. It should look like that

http://lh4.ggpht.com/_cAQDpIBg5Bg/S3glj2MIo6I/AAAAAAAAAIk/SN9vEwOEYCY/scale.jpg

Text alignment within the area is Horizontal Centered, Vertical Centered
Text wrap is on
Font is Arial, initial size is 10

Is it possible to implement?

13 Replies

Avatar

Level 10

Hi,

Set textfield to multiline and in the font tab set the font size to "0".

Parallels Desktop1.png

Sample attached.

Niall

Avatar

Former Community Member

Thanks a lot!

It is working!

One more question how to define the default font size for such element?

I've created a test form with one textfield. Set the font size to 0 and as the result if I put only one char its initial size is about 12. But I would like to set the initial size as 10.

Best,

Sergey

Avatar

Level 10

Hi,

I don't think so. Any scripting to force an initial font size, overrides the 0pt and then the text will not automatically reduce.

12pt initially or nothing, as far as I know.

Niall

Avatar

Former Community Member

Hi Niall,

Let assume default font size is 10 then can I check in a script that text is not filled within the area and switch the font size to 0?

It would be the best variant for me.

Regards,

Sergey

Avatar

Level 10

Hi Sergey,

Attached is an update - check  the enter and exit events. It may work for you, but you would want to test.

Good luck,

Niall

Avatar

Former Community Member

Hi Niall,

Is it possible within a script to check that a text string is to long to fit a textfield element?

For example there is a texfield element with autoexpand enabled. In the script remember width and height of the element, then assign a text sting and after it check new height and width. If they have changed then disable autoexpand, restore original width and height and set the font size to 0.

Or do something similar because I'm not a professional in scripting...

Best,

Sergey

Avatar

Level 10

Hi,

That is what the script in the last example is trying to do. You have to be careful, because if you turn the script around, it can end up turning off the auto reduce (0pt).

In the sample I have tested against 33 characters in the textfield. If you field is smaller then you would need to adjust this up or down.

It is doing this on the enter/exit events, because it was flaky when trying it on the change event. When typing in the data, the font size should be 0pt.

If you try a few alternatives, you may get it working like you want it.

Niall

Avatar

Former Community Member

Hi Niall

Could you post the source code from your PDF here?

I've tried several methods but I've been unsuccessful.

If I set autoexpand I cannot request width and height of a element (they are always 0 in the respective properties) the same applies for the font size property when font size is set to 0.

I do not want to program a threshold counter which will be measured in characters and set the font size to 0 if current characters count is above the threshold value because I'm using a variable width font like Arial. I consider it as the last chance decision now...

Best,

Sergey

Avatar

Level 10

Hi Sergey,

Here is the form. Below is an abstract from the XML source tab, but I would not be included to start pasting this into your form - it is better to work within the Design tab.

<field name="TextField1" w="44.45mm" h="22.225mm">

            <ui>

               <textEdit multiLine="1">

                  <border>

                     <?templateDesigner StyleID aped3?>

                     <edge stroke="lowered"/>

                  </border>

                  <margin/>

               </textEdit>

            </ui>

            <font typeface="Myriad Pro" size="0pt"/>

            <margin topInset="1mm" bottomInset="1mm" leftInset="1mm" rightInset="1mm"/>

            <para vAlign="middle" hAlign="center"/>

            <event activity="exit" name="event__exit">

               <script contentType="application/x-javascript">

if (this.rawValue.length &lt; 33)

{

     this.font.size = "10pt";

}

else

{

     this.font.size = "0pt";

}

</script>

            </event>

            <event activity="enter" name="event__enter">

               <script contentType="application/x-javascript">

this.font.size = "0pt";

</script>

           </event>

         </field>

I think you are going to have difficulty with the width and height of the element as these are going to be static. I would be inclined to count the number of characters that are the widest in Arial ("X" ?) and then amend the script.
Otherwise just work with the default 12pt for occasions where the auto reduction hasn't kicked in because there isn't overflow.
Good luck,
Niall

Avatar

Former Community Member

Hi Niall

this.rawValue.length &lt; 33

I'm trying to avoid this...

Do you know a way how to check that a text cannot fit the element or check that element has been expanded?

Best,

Sergey

Avatar

Level 10

OK,

This contains a second sample, where the textfield is set to 10pt and limits content to visible area:

Parallels Desktop1.png

But in this case the script is in the full event - setting the font to 0pt.

However it is not smooth - the user gets a beep when the field is full and has to exit and go back into the field to get the text to reduce in size.

This is as far as I can take it.

Hope that helps,

Niall

Avatar

Former Community Member

Unfortunately I forget to mention that in my case this field is to be read only and should be designed to represent a text string from the SAP system.

Regards,

Sergey

Avatar

Level 10

Hi Sergey,

In that case, I think the only options are:

  1. Leave the font to "0pt" and accept that in some situations short strings will be 12pt.
  2. Determine the number of characters that on average will fit into the field at 10pt. Then use the script to test the length of the string before it populates the field. If it is less than the max number of characters set the font size to 10pt. If it is more then set the font to 0pt.

I appreciate that this is not ideal, but I really think these are your only options.

Good luck,

Niall