views:

45

answers:

1

Is there a way to adjust columnwidth automatically to fit as much content in them as they can (sort of like double click a column width is a grid control).

At the moemnt I am setting them as percentages, but as there is different content dependign on search criteria, I would like the column width to adjust approprietaly.

I am currently setting the widths as below:

        var table = new PdfPTable(9) {WidthPercentage = 100};
        var colWidthPercentages = new[] {6f, 10f, 10f, 10f, 20f, 20f, 8f, 8f, 8f};
        table.SetWidths(colWidthPercentages);  

Does anyone know how to do this, or if not, a way to find out the optimum width a column would need to be to fit its content?

+1  A: 

You can use

XGraphics.MeasureString( string, XFont )

See this question : http://stackoverflow.com/questions/901304/calculate-text-height-based-on-available-width-and-font

mathieu