开发者

C# iTextSharp AutoAdjust column widths

开发者 https://www.devze.com 2023-01-12 00:03 出处:网络
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).

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 moment I am setting them as percentages, but as there is different content depending on search criteria, I would like the column width to adjust appropriately.

I am currently setting the widths as below:

var table = new PdfPTable(9) {WidthP开发者_Go百科ercentage = 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?


You can use

XGraphics.MeasureString( string, XFont )

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

0

精彩评论

暂无评论...
验证码 换一张
取 消