title: Export to pdf in MVC 4(Embed Html in pdf)
body: <p>I am  trying to export pdf using MVC 4. While exporting when trying to embed Html in pdf document error occur:</p>
  
  <ul>
  <li>The type or namespace name 'tool' does not exist in the namespace
  'iTextSharp'</li>
  </ul>
  
  <p>I have added  iTextSharp.dll but i dont know why i am getting error. Please help me thanks in advance.</p>
  
  <p>below is my method:</p>
  
  <pre><code>  public FileResult ExportData()
      {
          List&lt;Tb_ModalListFileUpload&gt; objlist = new List&lt;Tb_ModalListFileUpload&gt;();
  
          objlist = (from p in obj.Tb_ModalListFileUpload select p).ToList();
  
          WebGrid wd = new WebGrid(source: objlist, canPage: false, canSort: false);
  
          string griddata = wd.GetHtml(
          columns: wd.Columns
          (
          wd.Column(columnName: "SRNO", header: "SRNO"),
          wd.Column(columnName: "ModelName", header: "Model Name"),
          wd.Column(columnName: "ModelCC", header: "Model CC"),
  
          wd.Column(columnName: "ModelRate", header: "Model Rate"),
          wd.Column(columnName: "ModelRC", header: "Model RC"),
          wd.Column(columnName: "IncWith0", header: "Inc With 0"),
          wd.Column(columnName: "IncWith50", header: "Inc With 50"),
          wd.Column(columnName: "Provisional", header: "Provisional"),
          wd.Column(columnName: "NetPriceWith0", header: "Net Price With 0"),
          wd.Column(columnName: "NetPriceWith50", header: "Net Price With 50")
  
          )
          ).ToString();
  
          string exportData = String.Format("&lt;html&gt;&lt;head&gt;{0}&lt;/head&gt;&lt;body&gt;{1}&lt;/body&gt;&lt;/html&gt;", "&lt;style&gt;table{ border-spacing: 10px; border-collapse: separate; }&lt;/style&gt;", griddata);
          var bytes = System.Text.Encoding.UTF8.GetBytes(exportData);
          using (var input = new MemoryStream(bytes))
          {
              var output = new MemoryStream();
              var document = new iTextSharp.text.Document(PageSize.A4, 50, 50, 50, 50);
              var writer = PdfWriter.GetInstance(document, output);
              writer.CloseStream = false;
              document.Open();
  
              var xmlWorker = iTextSharp.tool.xml.XMLWorkerHelper.GetInstance();
              xmlWorker.ParseXHtml(writer, document, input, System.Text.Encoding.UTF8);
              document.Add(new Paragraph("Hello World!"));
              document.Close();
              output.Position = 0;
              return new FileStreamResult(output, "application/pdf");
          }
  
          }
  </code></pre>