Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting table height dynamically in iText

Tags:

dynamic

itext

Is there a way of getting the height of a table before adding it to the document?

At first glance, I supposed that the number of rows in the table is enough to calculate height since I know the font size. However, some rows break that rule. For instance, one cell might store a paragraph that has more than one line. Hence, what I need to know is the total of the heights of every row.

like image 879
caca Avatar asked Oct 19 '25 01:10

caca


1 Answers

Yeah, answer was not complicated.

In order to get the height of a table, one must set the width of the table first. In other words,

table.setTotalWidth((PageSize.A4.getWidth() - document.leftMargin()
- document.rightMargin()) * table.getWidthPercentage() / 100);

System.out.println(table.calculateHeights());

does give the height of the table.

like image 162
caca Avatar answered Oct 22 '25 04:10

caca