JayDS (3) [Avatar] Offline
#1
I'm sure I'm overlooking something obvious, but how do I determine how many columns are in a PdfPTable? The Table class has the getColumns() method, but I don't see anything analagous on PdfPTable. About the closest thing I see is to invoke getAbsoluteWidths() and the length of the returned array is the number of columns.
blowagie (284) [Avatar] Offline
#2
Re: How do I retrieve the number of columns in a PdfPTable?
You are not overlooking something obvious. There is no getNumberOfColumns() method in PdfPTable. Why not? Because nobody has felt the need for such a method since the introduction of PdfPTable on August 1, 2001. Why didn't anybody need such a method? Not because nobody is using PdfPTable (on the contrary!), but because the number of columns is a minimum requirement to construct a PdfPTable. If you construct a PdfPTable, you know the number of columns. If you know the number of columns, what's the point of having a getNumberOfColumns() method?
Maybe if you construct the PdfPTable using HTMLWorker, then it would make sense. But up till now, I haven't met anyone who needed to 'change' or 'investigate' objects after they were created with HTMLWorker.
If it's really necessary I'll add a getNumberOfColumns() method to PdfPTable for the next version.
JayDS (3) [Avatar] Offline
#3
Re: How do I retrieve the number of columns in a PdfPTable?
I can understand that rationale, but here's my situation: I'm constructing multiple tables in various subclasses of an abstract class which implements some interface. Each subclass creates a table with a different number of columns. The abstract class has various convenience methods to add different kinds of cells, some of which need to span the entire table. The thing invoking these methods doesn't know what kind of subclass (or table) it has, it just has the interface. The one thing it does have and that gets passed to the method is the table.

Basically, I'm implementing the Visitor pattern to construct tables for various types of records. Since each type of record is different, the columns in the tables are different. But each table also needs some common headers and footers which span the entire table.

Since this is just a first pass at it, I can change my implementation so that I don't need to ask the table for its number of columns. Since no one else has found it necessary to do so, that obviously is the way to go. Thanks!
blowagie (284) [Avatar] Offline
#4
Re: How do I retrieve the number of columns in a PdfPTable?
Incidentally I had a large TODO list of small extra features scheduled for today, and while I was at it, I added the getNumberOfColumns method. See http://itext.svn.sourceforge.net/viewvc/itext/trunk/src/core/com/lowagie/text/pdf/PdfPTable.java?view=log

This method will be available in iText 2.1.1 (release scheduled for today or tomorrow).