title: Convert HTML content to Pdf using c# and asp.net
body: <p>Here i am trying to convert the content inside <strong>html div tag to pdf</strong> i found the following error:</p>
  
  <p><strong>Input string was not in a correct format is occur</strong></p>
  
  <p>Here is the code i tried using c#:</p>
  
  <pre><code>public string getWhileLoopData()
  {
   string htmlStr = "";
   SqlConnection thisConnection = new SqlConnection("Data Source=VELU-PC\\SQLEXPRESS;Initial Catalog=EEP;Trusted_Connection=True;");
          SqlCommand thisCommand = thisConnection.CreateCommand();
          thisCommand.CommandText = "select * from Product_category";
          thisConnection.Open();
          SqlDataReader reader = thisCommand.ExecuteReader();
          while (reader.Read())
          {
              string id = reader.GetString(6);
              string Name = reader.GetString(3);
              string Pass = reader.GetString(5);
              htmlStr += "&lt;tr&gt;&lt;td&gt;&lt;table width='200px'&gt;&lt;tr&gt;&lt;td align='center'&gt;&lt;img src=" + id + " /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td align='center'&gt;" + Name + "&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;td&gt;&lt;table width='600px'&gt;&lt;tr&gt;&lt;td align='left' style='border:1px solid blue;border-radius:7px;box-shadow: 10px 0 10px #888888; padding: 8px 6px 0 7px;'&gt;Features: &lt;br/&gt;&lt;p style='margin-top: 10px;'&gt;" + Pass + "&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/td&gt;&lt;/tr&gt;";               
          }
          thisConnection.Close();
          return htmlStr;
  }    
  void generatetable()
  {
      divexcel.Visible = true;
      Response.ContentType = "application/pdf";
      Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
      Response.Cache.SetCacheability(HttpCacheability.NoCache);
      StringWriter sw = new StringWriter();
      HtmlTextWriter hw = new HtmlTextWriter(sw);
      divexcel.RenderControl(hw);
      StringReader sr = new StringReader(sw.ToString());
      Document pdfDoc = new Document(PageSize.A4, 80f, 80f, -2f, 35f);
      HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
      PdfWriter writer = PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
      pdfDoc.Open();
      htmlparser.Parse(sr);
      pdfDoc.Close();
      Response.Write(pdfDoc);
      Response.End();
  }
  public override void VerifyRenderingInServerForm(System.Web.UI.Control control)
  { }
  protected void button_Click(object sender, EventArgs e)
  {
      generatetable();
  }
  </code></pre>
  
  <hr>
  
  <p>Here is my html code:</p>
  
  <pre><code>        &lt;div id="divexcel" runat="server"&gt;
      &lt;table&gt;&lt;tr&gt;&lt;td&gt;&lt;asp:Button ID="button" runat="server" Text="Submit" 
          onclick="button_Click" /&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
      &lt;table align="center" width="100%"&gt;
          &lt;tr&gt;
              &lt;td&gt;
                  &lt;table&gt;
                      &lt;tr&gt;&lt;td align="center"&gt;ID&lt;/td&gt;&lt;/tr&gt;
                      &lt;tr&gt;&lt;td align="center"&gt;Name &lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;table&gt;
                      &lt;tr&gt;&lt;td align='left'&gt;Features: &lt;br/&gt;&lt;p&gt;Pass&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt;
                  &lt;/table&gt;
              &lt;/td&gt;
              &lt;/tr&gt;                       
  
          &lt;%=getWhileLoopData()%&gt;
  
      &lt;/table&gt;
  
  
      &lt;/div&gt;
  </code></pre>