dev 0

dev 0

  • NA
  • 31
  • 35.5k

How to set widths of column of pdfptable same as database column using itextsharp

Sep 27 2011 3:28 AM

Hi
I am doing code in C#.
I have created table using itextsharp, and binding my table with database,
so at every time i have no any idea about how many columns.
and i want my table in which column width is adjustable as par my data which is coming from database.
 
In below code ,if and only if, i know how much columns are their (in below case i.e 2 columns) so i used 2 width here ,
Collapse | Copy Code
PdfPTable pdfTable = new PdfPTable(table.Columns.Count);
iTextSharp.text.Rectangle rect = PageSize.LETTER;
float pageWidth = rect.Width;
if (pdfTable != null)
{
pdfTable.SetWidthPercentage(
new float[] {
(float).15 * pageWidth ,
(float).15 * pageWidth,
}, rect);

but when we have no any idea about number of columns(i.e when i binding pdfptable with my database) ,i can get count of columns , but how to set widths to each column widths as per data from database.
so plz help me.