title: ItextSharp Error on trying to parse html for pdf conversion
body: <p>I was using the ItextSharp module to convert the below listed html in to a pdf page.</p>
  
  <pre><code>        &lt;div style="font-size: 18pt; font-weight: bold;"&gt;
      mma&lt;br&gt;mmar&lt;/div&gt;&lt;br&gt; &lt;br&gt;
      &lt;div style="font-size: 14pt;"&gt;Click to View Pricing
      &lt;/div&gt;
      &lt;br&gt;
      &lt;div&gt;
      &lt;table&gt;
      &lt;tr&gt;&lt;td&gt; &lt;a href="http://www.mma.com/fci" style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt; FCI&lt;/a&gt;:&lt;/td&gt; 
  &lt;td&gt;&lt;a href="http://www.mma.com/access/?pn=78211-014" style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt; 78211-014&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-009" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-009&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-006" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-006&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-007" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-007&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-003" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-003&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-005" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-005&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-008"
   style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-008&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-004" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-004&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-012" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-012&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-007LF" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-007LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-015LF" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-015LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-003LF"
   style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-003LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-009LF" 
  style="color: Blue; font-size: 10pt; text-decoration:
  underline;"&gt;78211-009LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-005LF" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-005LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-010LF" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-010LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-006LF"
   style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-006LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-014LF"
   style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-014LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-004LF" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-004LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-012LF"
   style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-012LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-008LF"
   style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-008LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;
  &lt;a href="http://www.mma.com/access/?pn=78211-011LF" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-011LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;a href="http://www.mma.com/access/?pn=78211-013LF" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-013LF&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;a href="http://www.mma.com/access/?pn=78211-010" style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-010&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;/td&gt;
  &lt;td&gt;&lt;a href="http://www.mma.com/access/?pn=78211-015"
   style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt;78211-015&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt; 
  &lt;a href="http://www.mma.com/souriau" 
  style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt; Souriau&lt;/a&gt;:&lt;/td&gt;
   &lt;td&gt;&lt;a href="http://www.mma.com/access/?pn=24JR124-3" style="color: Blue; font-size: 10pt; text-decoration: underline;"&gt; 24JR124-3&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;
  </code></pre>
  
  <p>C# code to generate the html above : </p>
  
  <pre><code> var html = new StringBuilder(@"&lt;div style=""font-size: 18pt; font-weight: bold;""&gt;Authorized Distributor&lt;/div&gt;&lt;br&gt; &lt;br&gt;&lt;div style=""font-size: 14pt;""&gt;Click to View Pricing, Inventory, Delivery &amp; Lifecycle Information:&lt;/div&gt;&lt;br&gt;");
              List&lt;MfrBrandView&gt; mfrBrands = MfrBrandView.Load(fileId);
              var uniquesuppliers = mfrBrands.GroupBy(t =&gt; new {t.Manufacturer,t.SupplierVirtualDirectory}).Select(g =&gt; g.First());
              html.Append("&lt;div&gt;&lt;table&gt;");
              foreach (var uniquesupplier in uniquesuppliers)
              {
                  var mfrPartNums =
                      mfrBrands.Where(t =&gt; t.ManufacturerId == uniquesupplier.ManufacturerId).Select(
                          t =&gt; t.ManufacturerPartNumber).ToList();
                  html.AppendFormat(@"&lt;tr&gt;&lt;td&gt; &lt;a href=""http://www.mma.com/{0}"" style=""color: Blue; font-size: 10pt; text-decoration: underline;""&gt; {1}&lt;/a&gt;:&lt;/td&gt; &lt;td&gt;&lt;a href=""http://www.mma.com/access/?pn={2}"" style=""color: Blue; font-size: 10pt; text-decoration: underline;""&gt; {2}&lt;/a&gt;&lt;/td&gt;&lt;/tr&gt;", uniquesupplier.SupplierVirtualDirectory, uniquesupplier.MouserizationLabel, mfrPartNums[0]);
  
                  for (int i = 1; i &lt; mfrPartNums.Count(); i++)
                  {
                      html.AppendFormat(
                          @"&lt;tr&gt;&lt;td&gt;&lt;/td&gt; &lt;td&gt;&lt;a href=""http://www.mma.com/access/?pn={0}"" style=""color: Blue; font-size: 10pt; text-decoration: underline;""&gt;{0}&lt;/td&gt;&lt;/tr&gt;",
                          mfrPartNums[i]);
                  }
              }
              html.Append("&lt;/table&gt;&lt;/div&gt;");
              return html.ToString();
  </code></pre>
  
  <p>Code to generate the page after html is formed:</p>
  
  <pre><code>PdfWriter writer = null;
              PdfDocument doc = null;
              //PdfReader reader = new PdfReader(content);
             // reader.Info["Title"]
  
              try
              {
                  doc = new PdfDocument();
                  doc.SetPageSize(PageSize.LETTER);
                  writer = PdfWriter.GetInstance(doc, content);
                  writer.CloseStream = false;
                  doc.Open();
                  doc.NewPage();
  
                  foreach (IElement element in iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(html), null))
                  {
                      doc.Add(element);
                  }
              }
  </code></pre>
  
  <p>below is where i get an exception saying <strong><em>"Unable to cast object of type</em></strong> <em><strong>'iTextSharp.text.html.simpleparser.CellWrapper' to type 'iTextSharp.text.Paragraph'</em></strong>."
  <strong><code>iTextSharp.text.html.simpleparser.HTMLWorker.ParseToList(new StringReader(html), null)</code></strong></p>
  
  <p>Is there something wrong with the html I'm trying to parse? Is there a better way of doing this? 
  Thanks much in advance for your help. It's very much appreciated.</p>