在iText中动态获取表格高度 [英] Getting table height dynamically in iText
本文介绍了在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.
推荐答案
是的,答案并不复杂.
为了获得桌子的高度,必须首先设置桌子的宽度.换句话说,
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());
给出桌子的高度.
这篇关于在iText中动态获取表格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文