title: iTextSharp XmlWorker: right-to-left
body: <p>After a long time of struggling with this not-so-friendly API, I am finally making progress, but now I've come to a really nasty issue.. I have placed "dir" attributes in various places in my html with the value being "rtl".. but the XMLWorker doesn't seem to respect that at all. Does anyone know of a workaround? Here's my method:</p>
  
  <pre><code>public static void Generate&lt;TModel&gt;(string templateFile, TModel model, string outputFile, IEnumerable&lt;string&gt; fonts)
          {
              string template = System.IO.File.ReadAllText(templateFile);
              string result = Razor.Parse(template, model);
  
              using (var fsOut = new FileStream(outputFile, FileMode.Create, FileAccess.Write))
              using (var stringReader = new StringReader(result))
              {
                  var document = new Document();
                  var pdfWriter = PdfWriter.GetInstance(document, fsOut);
                  pdfWriter.InitialLeading = 12.5f;
                  document.Open();
  
                  var xmlWorkerHelper = XMLWorkerHelper.GetInstance();
  
                  var cssResolver = new StyleAttrCSSResolver();
                  //cssResolver.AddCss(cssFile);
  
                  var xmlWorkerFontProvider = new XMLWorkerFontProvider();
  
                  foreach (string font in fonts)
                  {
                      xmlWorkerFontProvider.Register(font);
                  }
  
                  var cssAppliers = new CssAppliersImpl(xmlWorkerFontProvider);
                  var htmlContext = new HtmlPipelineContext(cssAppliers);
                  htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
  
                  PdfWriterPipeline pdfWriterPipeline = new PdfWriterPipeline(document, pdfWriter);
                  HtmlPipeline htmlPipeline = new HtmlPipeline(htmlContext, pdfWriterPipeline);
                  CssResolverPipeline cssResolverPipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
                  XMLWorker xmlWorker = new XMLWorker(cssResolverPipeline, true);
                  XMLParser xmlParser = new XMLParser(xmlWorker);
                  xmlParser.Parse(stringReader);
  
                  document.Close();
              }
          }
  </code></pre>