I'm putting together a report via ItextSharp and I've read about how to assign specific widths to the PdfPTable columns, however I would like this width to be automatically assigned according to the content of the columns.
Any ideas?
I'm putting together a report via ItextSharp and I've read about how to assign specific widths to the PdfPTable columns, however I would like this width to be automatically assigned according to the content of the columns.
Any ideas?
Considering that the report is constructed from an array containing the contents of the table, and a vector containing its header, then just use this method to get the vector with the appropriate sizes of the columns.
Public Function getColsize(ByVal Dados(,) As String, ByVal Header As String(), ByVal FtCalculo As Font)
Dim L As Integer
Dim C As Integer
Dim nLin As Integer
Dim nCol As Integer
Dim Colsize() As Integer
Dim chk As Chunk
nCol = Dados.GetUpperBound(1)
nLin = Dados.GetUpperBound(0)
ReDim Colsize(nCol)
Dim B As BaseFont = FtCalculo.GetCalculatedBaseFont(False)
For C = 0 To nCol
'chk = New Chunk(Header(C).ToUpper, Ft2)
'Colsize(C) = Math.Ceiling(chk.GetWidthPoint)
Colsize(C) = Math.Ceiling(B.GetWidthPoint(Header(C).ToUpper, FtCalculo.Size)) + 2
Next C
For C = 0 To nCol
For L = 0 To nLin
chk = New Chunk(Dados(L, C), FtCalculo)
If Colsize(C) < (Math.Ceiling(chk.GetWidthPoint) + 2) Then
Colsize(C) = (Math.Ceiling(chk.GetWidthPoint) + 2)
End If
Next L
Next C
Return Colsize
End Function