title: Referencing external css file with XMLWorker
body: <p>I have switched from <strong><em>HtmlWorker</em></strong> to <strong><em>XMLWorker</em></strong> in order to take advantage of the use of <em>external css files</em>. Besides, in this way, I avoid the use of inline styling.</p>
  
  <p>This is currently my code:</p>
  
  <pre><code>public ActionResult ViewPdf(object model)
      {
          var doc = new Document(PageSize.A3, 10f, 1f, 10f, 30f);
  
          var memStream = new MemoryStream();
          var writer = PdfWriter.GetInstance(doc, memStream);
          writer.CloseStream = false;
  
          doc.Open();
  
          var xmltext = RenderActionResultToString(View(model));
  
          var htmlContext = new HtmlPipelineContext(null);
          htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
  
          var cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
          cssResolver.AddCssFile(Server.MapPath("~/Content/StyleSheet1.css"), true);
  
          var pipeline = new CssResolverPipeline(cssResolver,
                                                 new HtmlPipeline(htmlContext, new PdfWriterPipeline(doc, writer)));
  
          var worker = new XMLWorker(pipeline, true);
          var parser = new XMLParser(worker);
  
          using (var sr = new StringReader(xmltext))
          {
  
              parser.Parse(sr);
          }
  
  
          doc.Close();
  
          var buf = new byte[memStream.Position];
          memStream.Position = 0;
          memStream.Read(buf, 0, buf.Length);
  
          return new BinaryContentResult(buf, "application/pdf");
      }
  </code></pre>
  
  <p><strong>RenderActionResultToString(View(model))</strong> is giving me the string I want to parse into pdf. This all works fine. The problem is with the styles. If I use inline styling such as:</p>
  
  <pre><code>&lt;table style ="width: 400px"&gt;
  </code></pre>
  
  <p>, everything works like a charm. But if I use something like:</p>
  
  <pre><code>&lt;table class = "foo"&gt;
  </code></pre>
  
  <p>, and reference a css file(StyleSheet1.css) like this:</p>
  
  <pre><code>.foo {
      width: 400px;
  }
  </code></pre>
  
  <p>, it doesn't work...</p>
  
  <p>I tried referencing the stylesheet in the string I am parsing, like this in my view:</p>
  
  <pre><code>    &lt;head&gt;
          &lt;link href ="@Server.MapPath("~/Content/StyleSheet1.css")" rel ="stylesheet" type="text/css"/&gt;  
      &lt;/head&gt;
  </code></pre>
  
  <p>I inserted the link to the css file just as the <a href="http://demo.itextsupport.com/xmlworker/itextdoc/flatsite.html" rel="nofollow">documentation</a> states, inside the head tags.</p>
  
  <p>Thanks in Advance</p>