How can i set itextSharp PdfPTable column width
C#
1
Posts
1
Posters
0
Views
1
Watching
-
In the sample code below, how can i set varying column widths for each column individually? The DescriptionColumnName width is expected to be much wider than other columns and Col1Name is not expected to be equal to Col2Name in width?. Currently, all columns are being returned with the same column width, and the description column in most cases contains alot of free text, so i want to reduce the width of columns Col1Name & Col2Name and then increase DescriptionColumnName width.
Document document; document.NewPage(); System.Collections.ArrayList columnWidth = new System.Collections.ArrayList(); for (int i = 0; i < this.dataTable.Columns.Count; i++) { if (i < 2) { columnWidth.Add(2f); } else { columnWidth.Add(1f); } } float\[\] headerWidths = columnWidth.OfType().Select(w => (float)w).ToArray(); PdfPTable tableHeader = new PdfPTable(3); tableHeader.AddCell(GetCell(Col1Name)); tableHeader.AddCell(GetCell(Col2Name)); tableHeader.AddCell(GetCell(DescriptionColumnName)); tableHeader.SetWidths(headerWidths); tableHeader.HeaderRows = 1; PopulatePDFCell(tableHeader); document.Add(tableHeader);
"Coming soon"