Automatic font size reduction in a PDF form | Community
Skip to main content
February 15, 2010
Question

Automatic font size reduction in a PDF form

  • February 15, 2010
  • 13 replies
  • 24073 views

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?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

13 replies

Niall_O_Donovan
Level 10
February 15, 2010

Hi,

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

Sample attached.

Niall

February 15, 2010

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

Niall_O_Donovan
Level 10
February 15, 2010

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

February 15, 2010

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

Niall_O_Donovan
Level 10
February 15, 2010

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

February 15, 2010

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

Niall_O_Donovan
Level 10
February 15, 2010

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

February 15, 2010

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

Niall_O_Donovan
Level 10
February 15, 2010

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

February 15, 2010

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