Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

How can I query the rendered width of a text object

Avatar

Former Community Member

Does anyone know of a way to query the rendered width of a bound field object. We are using a proportional font (Times New Roman) and need to figure out, how wide the output is going to be. Thank you!

6 Replies

Avatar

Level 10

Hi,

You can access the width of the object using .w. For example:

var vWidth = TextField1.w; 

Hope that helps,

Niall

Avatar

Former Community Member

Hi Niall, thank you, but this is not what I need. Say, for instance, I have a field "FirstName" defined with w=3.0in and font="Times New Roman", fontsize="12pt". The first record from the dat file has the value "Niall", the second record has the value "Alexander". What I need is the resulting length of the strings "Neill" and "Alexander".  Counting characters doesn't help, because the width of the different characters varies.

Avatar

Level 10

Hi,

.w will give the width of the field. Are you flowing the field Western style, so that it automatically extends based on the length of the string?

Maybe if you describe what you are looking for. When the data is imported, do you want the object to change in width? Or do you want the font to reduce in size to fit the content into a fixed sized object?

Sorry, but I just don't understand whay you need the physical length of the string inside a field. Can you explain?

Niall

Avatar

Former Community Member

Hi Niall, thanks again. I am currently working on a project where we convert Crystal Reports

documents to LiveCycle Production Print with the goal of creating the exact same output in

LiveCycle as it was produced in Crystal Reports.

We define a field in LiveCycle with the exact same properties for width, height, font, font size etc. as

it is defined in Crystal Reports.

When we populate the field with data that exceeds the defined width of the field, the data gets cut

off at a different position than in Crystal Reports, sometimes even in the middle of a character.

If I could query the length of the rendered output, I could shorten the input data until the rendered

output would fit in the field.

Avatar

Former Community Member

I think that you are looking for something like this:

var

oW = xfa.layout.w(txtDescription, "in");

The paramaters that are passed are the field name and the units that you want the result returned in. This will give you the width of the field after layout has occured (so if a field is dynamic you are getting the width after the field has been expanded).

Paul

Avatar

Former Community Member

Thank you Paul!!

That is exactly what I needed. I appreciate your help.

Alex