2

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:

public static void Generate<TModel>(string templateFile, TModel model, string outputFile, IEnumerable<string> 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();
            }
        }
j0k
  • 22,600
  • 28
  • 79
  • 90
Matt
  • 6,787
  • 11
  • 65
  • 112
  • 2
    See this page which has a list of supported HTML tags and attributes in the `XMLWorker`. You'll see that `dir` is not on there and if I were to guess, you won't see it in the near future, either. http://demo.itextsupport.com/xmlworker/itextdoc/flatsite.html#itextdoc-menu-18 – Chris Haas May 09 '12 at 13:22

1 Answers1

1

I've created a sample to show how to parse and display RTL data using XMLWorker. Download it from here.

VahidN
  • 18,457
  • 8
  • 73
  • 117
  • Hey @VahidN i need to convert html to pdf very much but i couldnt :-(, i used your class but i found out that just table and span tags can convert, i changed your sample html variable, as i said it could not convert div or other tags, can u help me. – A Programmer Mar 31 '17 at 17:35