title: How to create dynamic pdf cells in C# mvc
body: <p>I have a view containing a table that has more than 30 columns which is changing with month i want to print it into pdf.But i need to create the pdf cell dynamically.ie if i select the month as august the pdf have 30 columns if i select february the pdf have 28 columns how can i do that anyone please help me.Below are the code.
  [![table to be print as pdf][1]][1]</p>
  
  <pre><code>Document pdfDoc = new Document(PageSize.A4, 40f, 40f, 30f, 30f);
  //     Document pdf = new Document(pageSize.A4,)
  PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
  pdfDoc.Open();
   PdfPTable tablebody = new PdfPTable(pdfCell);
  tablebody.TotalWidth = 500f;
   PdfPCell cell0 = new PdfPCell(new Phrase(" Georoof \n\n MONTHLY FIELD VISIT REPORT", new Font(Font.FontFamily.HELVETICA, 12f, Font.BOLD)));
  cell0.Colspan = 7;
  cell0.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
  cell0.PaddingBottom = 6f;
  cell0.PaddingTop = 6f;
  tablebody.AddCell(cell0);
  
  PdfPCell cell1 = new PdfPCell(new Phrase("Dealer", new Font(Font.FontFamily.HELVETICA, 10f, Font.BOLD)));
  cell1.Colspan = 1;
  cell1.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
  cell1.PaddingBottom = 6f;
  cell1.PaddingTop = 6f;
  tablebody.AddCell(cell1);
  
  PdfPCell cell2 = new PdfPCell(new Phrase("Executive", new Font(Font.FontFamily.HELVETICA, 10f, Font.BOLD)));
  cell2.Colspan = 1;
  cell2.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
  cell2.PaddingBottom = 6f;
  cell2.PaddingTop = 6f;
  tablebody.AddCell(cell2);
  
  PdfPCell cell3 = new PdfPCell(new Phrase("Days", new Font(Font.FontFamily.HELVETICA, 10f, Font.BOLD)));
  cell3.Colspan = 1;
  cell3.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
  cell3.PaddingBottom = 6f;
  cell3.PaddingTop = 6f;
  tablebody.AddCell(cell3);
  
  for (int i = 4, j = 4; i &lt;= DaysInMonth; i++)
  {
      string cells = i.ToString();
      PdfPCell cell = new PdfPCell(new Phrase(cells, new Font(Font.FontFamily.HELVETICA, 10f, Font.BOLD)));
  
      cell3.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
      cell3.PaddingBottom = 6f;
      cell3.PaddingTop = 6f;
      tablebody.AddCell(cell3);
      j++;
  }
  </code></pre>