C # iTextSharp AutoAdjust Column Width

Is there a way to adjust the column width automatically to place as much content in them as they can (sort of like double-clicking on the column width is grid control).

I am setting them as percentages at the moment, but since there is different content depending on the search criteria, I would like the column width to fit accordingly.

I am currently setting the width as shown 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, the way to find out the optimal column width should match its content?

+7
c # itext column-width
source share
1 answer

you can use

XGraphics.MeasureString (string, XFont)

See this question: Calculate text height based on available width and font?

+1
source share

All Articles