  | Mailing List | | Home | | Forum Home | | JBoss - Java Application Server | | Tomcat - JSP/Servlet container | | Struts - A MVC web framework | | iText - An open source PDF Java Library | | JDOM - JDOM XML Parser | | JSP - A mailing list about Java Server Pages specification and reference | | J2EE - A mailing list for Java(tm) 2 Platform, Enterprise Edition | | J2EE Pattern - An interest list for Sun Java Center J2EE Pattern Catalog | | Servlet - A mailing list for discussion about Sun Microsystem's Java Servlet API Technology | |
Struts & Hibernate
|
|
|
  | | | PdfPTable column widths | PdfPTable column widths 2007-12-03 - By Nik Kolev
Back Hi,
I have a couple of questions regarding column widths in a PdfPTable.
1) Is there a quick, out-of-the-box way to "tell" the table to set each column width to the width of the cell (among the cells in the column) with the maximum width?
2) If not, what's the best approach that you could recommend to do that? I have a document that contains a number of tables that are added one after another. The data and the metadata in each table vary at runtime (depending on the data type and the actual data the table represents). There are header rows which span multiple columns. What I see is that each column gets an even percent of the width of the table regardless of the data that it wraps. One approach that I tried but did not work (keep in mind that I've only been using iText for 2 days before trying to kill me) is keeping track of the width of the data of each cell in a given column, using ColumnText.getWidth(Phrase p) - p being used when constructing the PdfPCell-s; and at the end doing a table.setWidths with the max width of each column.
I apologize if this has already been addressed in a previous post, but a search and a quick scan did not find me a match.
Thanks, -nik
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas -microsoft-com:office:word" xmlns="http://www.w3.org/TR/REC-html40">
<head> <meta http-equiv=Content-Type content="text/html; charset=us-ascii"> <meta name=Generator content="Microsoft Word 11 (filtered medium)"> <style> <!-- /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:12.0pt; font-family:"Times New Roman";} a:link, span.MsoHyperlink {color:blue; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {color:purple; text-decoration:underline;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:Arial; color:windowtext;} @(protected) Section1 {size:8.5in 11.0in; margin:1.0in 1.25in 1.0in 1.25in;} div.Section1 {page:Section1;} --> </style>
</head>
<body lang=EN-US link=blue vlink=purple>
<div class=Section1>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'>Hi,<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'>I have a couple of questions regarding column widths in a PdfPTable.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'>1) Is there a quick, out-of-the-box way to “tell” the table to set each column width to the width of the cell (among the cells in the column) with the maximum width?<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'>2) If not, what’s the best approach that you could recommend to do that? I have a document that contains a number of tables that are added one after another. The data and the metadata in each table vary at runtime (depending on the data type and the actual data the table represents). There are header rows which span multiple columns. What I see is that each column gets an even percent of the width of the table regardless of the data that it wraps. One approach that I tried but did not work (keep in mind that I’ve only been using iText for 2 days before trying to kill me) is keeping track of the width of the data of each cell in a given column, using ColumnText.getWidth(Phrase p) – p being used when constructing the PdfPCell-s; and at the end doing a table.setWidths with the max width of each column.<o:p></o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'>I apologize if this has already been addressed in a previous post, but a search and a quick scan did not find me a match.<o:p></o:p></span>< /font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'><o:p> </o:p></span></font></p>
<p class=MsoNormal><font size=2 face=Arial><span style='font-size:10.0pt; font-family:Arial'>Thanks, -nik<o:p></o:p></span></font></p>
</div>
</body>
</html>
-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----- SF.Net email is sponsored by: The Future of Linux Business White Paper from Novell. From the desktop to the data center, Linux is going mainstream. Let it simplify your IT future. http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4 __ ____ ____ ____ ____ ____ ____ ____ ____ ____ iText-questions mailing list iText-questions@(protected) https://lists.sourceforge.net/lists/listinfo/itext-questions Buy the iText book: http://itext.ugent.be/itext-in-action/
|
|
 |