Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

iText trouble with automatically adjustment of table width

807606Mar 15 2007 — edited May 12 2007
With iText I an producing a PDF file with some elements. One of these is a table which is supposed to be centered.

In this table 2x2 with input form a Servlet. This input is a string of variable length, in other words I do not know the length of it.

I want this table to automatically adjust the cells width according to the length of the String. As I understand iText does not posess this functionality.

This is how I have created the table: The first column has a width of 0.3 because the values in those I allready know. The default value is centered and 80% span, and because of this the table is not centered according to the text since the content contains empty space, but the 80% span table is centered.
PdfPTable table = new PdfPTable(2);
float[] widths = { 0.3f, 0.8f };
table.setWidths(widths);
How could I calculate this? The string has a font size of 22pt. Could I check for the number of chars in the String and adjust the width accordingly? It seems like I need to set the table.setWidthPercentage(50) in addition to the width size. But if I dont know the relationship between the width and percentages.

If I calculate the width to be 0.6f with font size 22 and length x, how much percentages should I use?

Message was edited by:
DJ_Viking

Message was edited by:
DJ_Viking
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 9 2007
Added on Mar 15 2007
3 comments
2,071 views