开发者

How to make PdfPTable calculate column-width dynamically

开发者 https://www.devze.com 2023-04-11 05:08 出处:网络
I want to create a PdfPTable with columns containing Strings of different lengths. I learned that the width of each cell/column are the same for each column (default) or one can set开发者_开发问答 the

I want to create a PdfPTable with columns containing Strings of different lengths. I learned that the width of each cell/column are the same for each column (default) or one can set开发者_开发问答 the fraction of space every column shall occupy.

However, I want the columns to be as wide as required, but not any wider, depending on the data inserted. Assume that the table fits easily on the page (no breaks!). Of course, I can manually step through all my data and calculate the maximum-String-length of each column, setting the properties of the table accordingly, but I wondered whether such a common option is already provided by itext itself.


iText is not HTML, so it doesn't have options to automatically adjust width, instead is page oriented and so you've to decide your widths, either as percentage or absolute values.

I'm afraid that to do what you ask, you've to implement your own extension by measuring the widths, as you said. See how to calculate the string with with iText.

0

精彩评论

暂无评论...
验证码 换一张
取 消