title: iTextSharp - How to add canvas or image to pdf from HTML string using XMLWorkerHelper?
body: <pre><code>public string GetPDF(string pHTML)
      {
  
          byte[] pdf; // result will be here
  
          var cssText = System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/Content/bootstrap.css"));
          cssText=cssText + System.IO.File.ReadAllText(HttpContext.Server.MapPath("~/Content/styles.css"));
          var html = pHTML;
  
          using (var memoryStream = new MemoryStream())
          {
              var document = new Document(PageSize.A4, 15, 15, 15, 15);
              var writer = PdfWriter.GetInstance(document, memoryStream);
              document.Open();
  
              using (var cssMemoryStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(cssText)))
              {
                  using (var htmlMemoryStream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(html)))
                  {
                      XMLWorkerHelper.GetInstance().ParseXHtml(writer, document, htmlMemoryStream, cssMemoryStream);
                  }
              }
  
              document.Close();
  
              pdf = memoryStream.ToArray();
          }
          var temp = Convert.ToBase64String(pdf);
          return temp;
  
  
      }
  </code></pre>
  
  <p>I pass the html string from razor view to controller but image tag closing error shown when XMLWorkerHelper try to parse and if i direcly pass image tag string from code behind then no image shown</p>