I'm using the iTextSharp to export reports to PDF and I have a table with all content that I need.
I want to give columns width based on the most wide text of each column, but the GetWidtPoint()
method returns text width that I'm not expecting and the column content jumps to the next line.
Below, there is an example about the calculus of the header text width. I put all my table header inside an array first.
Dim ColSize(10) as single
Dim Ck as Chunk
For I = 0 to Colsize.getUpperBound(0)
Ck = new Chunk(Data(I),myFont)
Ck.SetCharacterSpacing(1)
Colsize(I) = Ck.GetWidthPoint
Next I
Finally, the table declaration...
Dim T as new PdfPtable(11)
T.HorizontalAligment = 0
T.WidthPercentage = 100
T.SpacingBefore = 3
T.setWidths(Colsize)
An example about issue:
Through the calculus method that I used, the GetWidthPoint()
returns 33 points to "Produto" word, but if i set the column width to 33f so I cant show this text only in the first line. To Show the entire word in the same line, I need to set the column width to 55f.
When i print the text in the cell...
Dim Cell as new PdfpCell(new Phrase(new Chunk(Data(I,X),Font)))
T.addCell(cell)
Any ideas?