RTL Support

Nov 30, 2013 at 8:58 PM
Edited Nov 30, 2013 at 8:58 PM
Hi,
I tried to add RTL support for my html. I added the RTL tag to every object but didn't worked:
                       var sb = new StringBuilder();
            sb.Append(@"<!DOCTYPE HTML PUBLIC ""-//W3C//DTD HTML 4.01 Transitional//EN"" ""http://www.w3.org/TR/html4/loose.dtd"">
                        <html xmlns=""http://www.w3.org/1999/xhtml"" dir=""rtl"">
                        <head>
</head><body dir=""rtl"" style=""direction:rtl"">");

            foreach (var item in data)
            {
                sb.Append(item.Content);
                sb.Append("<br/></br><br/></br>");
            }


            sb.Append("</body></html>");


            var css = HtmlRenderer.CssData.Parse("html { direction:rtl; text-align:right } body { direction:rtl; text-align:right } table { direction:rtl!important; }", true);

            

            var img = HtmlRenderer.HtmlRender.RenderToImage(sb.ToString(), 600,  cssData: css);

            img.Save(Path.Combine(path, "file.jpg"));
I'm using the latest version (1.4.10).

Thank you for you help.
Developer
Dec 1, 2013 at 8:20 AM
there is a bug with handling <br/> elements in RTL
Until I fix it you can set RTL only on div that has the content in it like so:
<html>
<style>
body { text-align:right }
</style>
<body>
<div dir="rtl">
שלום עולם יש ברבורים בעגם
</div>
<br/>
</body>
</html>
Note: currently the RTL support is very basic so make sure it works for you.