title: 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'
body: <p>While trying to create HTML to Pdf using itextsharp getting <em>Unable to cast object of type 'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'.</em> exception.Here is the piece of code </p>
  
  <pre><code>string FilePath = System.Web.HttpContext.Current.Server.MapPath("~/EmailTemplate/tenantStatement-print.html");
          StreamReader mstrFileStreamReader = new StreamReader(FilePath);
  
          string fileContents = mstrFileStreamReader.ReadToEnd();
  
          mstrFileStreamReader.Close();
  
          String htmlText = fileContents;
  
          Document document = new Document();
  
          PdfWriter.GetInstance(document, new FileStream(HttpContext.Current.Server.MapPath("~\\DocumentEngine\\tempDocs\\") + "\\outfile.pdf", FileMode.Create));
          document.Open();
          iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
          iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
          hw.Parse(new StringReader(htmlText));
          document.Close();
  
          Response.ClearContent();
          Response.ClearHeaders();
          Response.AddHeader("Content-Disposition", "inline;filename=outfile.pdf");
          Response.ContentType = "application/pdf";
          Response.WriteFile(HttpContext.Current.Server.MapPath("~\\DocumentEngine\\tempDocs\\") + "\\outfile.pdf");
          Response.Flush();
          Response.Clear();
  </code></pre>