Expand my Community achievements bar.

Enhance your AEM Assets & Boost Your Development: [AEM Gems | June 19, 2024] Improving the Developer Experience with New APIs and Events

How to count lines in TextField?


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


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!


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


Level 1

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


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