Expand my Community achievements bar.

SOLVED

finding height of multiLine textbox when it expands on multiple pages

Avatar

Level 2


Hello community,

A user requested me for a multiline texbox (expandable) with a column next to it that would display the row number of each line.

Because every character type can have their own height i figured id convert the text to courrier as each character use the same height.

My problem now is when the textbox expands on multiple pages, I can't get the total height of the textbox, only the height of the textbox on the first page

Unfortunately i cannot upload the form from work for security reason but here is the code.

var txt_CompteRendu = xfa.resolveNode("formulaire1.page2.sf7.table7.row7_1.Tableau22.row2.txt71_CompteRendu");
var p2_lbl_rowCount = xfa.resolveNode("formulaire1.page2.sf7.table7.row7_1.Tableau22.row2.lbl7_LineNum");

var lblText = "";

p2_lbl_rowCount.rawValue = "";

for (var i = 1; i * 10 <= (xfa.layout.h(txt_CompteRendu, "pt")); i++) {
    if (lblText != "") {
     lblText = lblText + "\n";
}
    lblText = lblText + i;
}
p2_lbl_rowCount.rawValue = lblText;
console.println(lblText);
xfa.layout.relayout(); // need to relayout so that if i remove lines it change the size of the row2 right away instead of having to put the focus on it again then out

the variable p2_lbl_rowCount is the text label use to display the line number.

Unfortunately if the textbox txt_CompteRendu is more than 72 lines it will expand to another page, at which point the counter will stop counting.

1 Accepted Solution

Avatar

Correct answer by
Level 2

Finally figured it out.

It seems like the textbox "txt_CompteRendu" is actually divided into multiple boxes when changing lines.

xfa.layout.h actually has an option to specify the textbox index

It the following code textHeight will take the height of the textbox if the text expand on 3 pages, it will also work  if the text expand on 2 pages or is only one one page.

var txt_CompteRendu = xfa.resolveNode("formulaire1.page2.sf7.table7.row7_1.Tableau22.row2.txt71_CompteRendu");
var p2_lbl_rowCount = xfa.resolveNode("formulaire1.page2.sf7.table7.row7_1.Tableau22.row2.lbl7_LineNum");
var textHeight = xfa.layout.h(txt_CompteRendu, "pt", 0) + xfa.layout.h(txt_CompteRendu, "pt",1) + xfa.layout.h(txt_CompteRendu, "pt",2);
var lblText = "";
console.println( textHeight );

p2_lbl_rowCount.rawValue = "";

for (var i = 1; i * 10 <= textHeight ; i++) {
    if (lblText != "") {
     lblText = lblText + "\n";
}
    lblText = lblText + i;
}
p2_lbl_rowCount.rawValue = lblText;

View solution in original post

2 Replies

Avatar

Correct answer by
Level 2

Finally figured it out.

It seems like the textbox "txt_CompteRendu" is actually divided into multiple boxes when changing lines.

xfa.layout.h actually has an option to specify the textbox index

It the following code textHeight will take the height of the textbox if the text expand on 3 pages, it will also work  if the text expand on 2 pages or is only one one page.

var txt_CompteRendu = xfa.resolveNode("formulaire1.page2.sf7.table7.row7_1.Tableau22.row2.txt71_CompteRendu");
var p2_lbl_rowCount = xfa.resolveNode("formulaire1.page2.sf7.table7.row7_1.Tableau22.row2.lbl7_LineNum");
var textHeight = xfa.layout.h(txt_CompteRendu, "pt", 0) + xfa.layout.h(txt_CompteRendu, "pt",1) + xfa.layout.h(txt_CompteRendu, "pt",2);
var lblText = "";
console.println( textHeight );

p2_lbl_rowCount.rawValue = "";

for (var i = 1; i * 10 <= textHeight ; i++) {
    if (lblText != "") {
     lblText = lblText + "\n";
}
    lblText = lblText + i;
}
p2_lbl_rowCount.rawValue = lblText;