title: iTextSharp add ( css style or a css file) and download pdf file
body: <p>Finally got it working</p>
  
  <pre><code>var inputString = @"&lt;html&gt;
  &lt;body&gt;
  &lt;table  class='table-bordered'&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;Customer Name&lt;/th&gt;
              &lt;th&gt;Customer's Address&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
  &lt;tbody&gt;
      &lt;tr&gt;
          &lt;td&gt; XYZ &lt;/td&gt;
          &lt;td&gt; Bhubaneswar &lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt; MNP &lt;/td&gt;
          &lt;td&gt; Cuttack &lt;/td&gt;
      &lt;/tr&gt;
  &lt;/tbody&gt;
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;";
  
  
  List&lt;string&gt; cssFiles = new List&lt;string&gt;();
  cssFiles.Add(@"/Content/bootstrap.css");
  
  var output = new MemoryStream();
  
  var input = new MemoryStream(Encoding.UTF8.GetBytes(inputString));
  
  var document = new Document();
  var writer = PdfWriter.GetInstance(document, output);
  writer.CloseStream = false;
  
  document.Open();
  var htmlContext = new HtmlPipelineContext(null);
  htmlContext.SetTagFactory(iTextSharp.tool.xml.html.Tags.GetHtmlTagProcessorFactory());
  
  ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
  cssFiles.ForEach(i =&gt; cssResolver.AddCssFile(System.Web.HttpContext.Current.Server.MapPath(i), true));
  
  var pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(document, writer)));
  var worker = new XMLWorker(pipeline, true);
  var p = new XMLParser(worker);
  p.Parse(input);
  document.Close();
  output.Position = 0;
  
  
  Response.Clear();
  Response.ContentType = "application/pdf";
  Response.AddHeader("Content-Disposition", "attachment; filename=myfile.pdf");
  Response.BinaryWrite(output.ToArray());
  // myMemoryStream.WriteTo(Response.OutputStream); //works too
  Response.Flush();
  Response.Close();
  Response.End();
  </code></pre>