Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn more

View all

Sign in to view all badges

How to count lines in TextField?

mr__broccoli
Level 1
Level 1

I have TextField designed like “multi line”, with “auto-fit” height.

Content (text) is filled by external data (via interface) in print scenario. Please help me how to read number of really utilized lines in JavaScript?

4 Replies
Magus069
Level 10
Level 10

Hi there,

if you want to verify how many lines there is text, and skip lines which are blank, you can use the following script to achieve what you need

If you want to verify how many line, counting the empty lines, use the following code

Hope this will help!

Magus069
Level 10
Level 10

This works if lines are created using enter, but it is not working if lines are created with excessive characters on one line... Sorry it is not working perfectly

mr__broccoli
Level 1
Level 1

Exactly. We tested and when line break exists due to long text (not hard ENTER), function charCodeAt() is not helpful.

yanip
Level 2
Level 2

I actually had to do something similar to what your looking for a couple of weeks again.

For it to work tho you must use courrier character ( from what i understand they are the only for which each character has the same height but im not sure)

finding height of multiLine textbox when it expands on multiple pages

for (var i = 0; xfa.layout.h(txt_CompteRendu, "pt", i) > 0; i++) {

  totLine = totLine + (xfa.layout.h(txt_CompteRendu, "pt", i) / 10);

}

Basically i take the height of the textbox "in pt but you could use mm / cm" and divide it by the height of  my characters (in my case 10).

THe reason i put it in a for loop is because my  textbox can grow on many pages, to access the textbox on each page you need to specify its index