suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

How do Browsers auto reverse the Right to left Text in Markup Languages

1 min read

You might have encountered a situation where you tried to read from pdf or other text input streams and writing the raw data into html pages which contains right to left languages; Unfortunately you would not be able to display right to left directional character as it was read from data input stream. You could see only the reversed output in html page which is not supposed to be reversed.

The cause of this issue is the ability of browsers that detect the right to left characters automatically and reverse the raw data into right to left direction. Eventually the result will be reversed in html display even it was already reversed in raw input stream.

You may find the characters under this Unicode Ranges display the text in right to left direction in html pages unless the chars mapped into other CID font values.

0x0590 – 0x05FF = Hebrew

0x0600 – 0x06FF = Arabic

0x0750 – 0x077F = Arabic Supplement

0xFB50 – 0xFDFF = Arabic Presentation forms-A

0xFE70 – 0xFEFF = Arabic Presentation Forms-B

You should take some factors into your account if you try to reverse these characters using javascript or other scripting languages because the special characters such as , ( ) [ ] ? % may give unanticipated meanings in these languages. Other interesting thing in Arabic language is Arabic letters are usually read from right to left but Arabic numerals are read from left to right. And it is also worth to bear in mind the cases where Arabic phrases are embedded in the middle of English characters.

So my recommendation to overcome this problem is to use bidirectional controls in div tags. This is one of the easiest way of forcing browsers to not to auto reverse the phrases. This can be done using right to left explicit control in <bdo> (Bi Directional Ordering) tag with dir=”ltr” attribute,  In which case you explicitly say the browsers to display characters in right to left direction.

Example <div><bdo dir=”ltr”>{raw data}</bdo></div>

However if you find your raw data is in wrong order you can use the same <bdo> tag with dir=”rtl” attribute. But again you should aware of Arabic numerals and phrases embedded between other Latin or special characters. It is recommended to use bi directional override status in these cases.

Fortunately there is no language exists in the world which reads from north east to south west or vice versa.

Are you a Developer working with PDF files?

Our developers guide contains a large number of technical posts to help you understand the PDF file Format.

Find out more about our software for Developers

Convert PDF to HTML5 or SVG Convert PDF to HTML5 or SVG
Convert AcroForms and XFA to HTML5Convert AcroForms and XFA to HTML5
Java PDF SDK for working with PDF files Java PDF SDK for working with PDF files
suda Senior Java EE Develope specialises in Pdf forms , Fonts, application servers and Image manipulation, meditates in spare time.

Leave a Reply

Your email address will not be published. Required fields are marked *

IDRsolutions Ltd 2021. All rights reserved.