Home Page Arabic text in FOP
Home
                              XSL-FO Server
                            • Getting started
                            • Versions
                            • How to
                            • XSL-FO Editor
                            • XSL-FO resources
                            • XSL-FO in REALbasic
                            • XSL-FO in Php
                            • XSL-FO in VB 6
                            • XSL-FO in .NET
                            • XSL-FO in Ruby
                            • XSL-FO in Delphi
                            • Usage with APEX
                            • Professional license
                            • Arabic text in FOP

                               

                              This articles describes how to add arabic text to PDF files using apache FOP and FO Designer 1.5.3 or later. 

                              What is special about arabic text is that it does not only requires specific font files but the characters will be shown is different ways (using different font glyphs) depending on the position of the character (you can find more information about ligatures here), so there is no one to one relationship between characters and glyphs as in other languages. Furthermore arabic text will be written from right to left as opposite to most languages that will be written from left to right.

                              In other to include arabic text in the PDF file, the first step is defining the font to be used. In this example we will use the trado.ttf font file which is available in windows 7.

                              1. edit the file tools/createFontMetrics.bat from the FO Designer installation and set the lines:

                                SET TTFFILE=c:\yourfontsdirectory\trado.ttf
                                SET OUTPUT=trado.xml

                              2. execute the  tools/createFontMetrics.bat to create the output file trado.xml

                              3. edit trado.xml and make sure both the <font-name> and the <family-name> tags contain the value TraditionalArabic

                              4. now edit the file fopUserConfig.xml in the FO Designer directory and add these lines (of course change the yourfontdirectory value):

                                <!-- register a particular font -->
                                <font metrics-url="file:///C:/yourfontsdirectoy/trado.xml" kerning="yes"
                                embed-url="file:///C:/yourfontsdirectoy/trado.ttf">
                                <font-triplet name="TraditionalArabic" style="normal" weight="normal"/>
                                </font>

                                you have to add this before the line

                                <!-- register all the fonts found in a directory -->

                                these lines will tell Apache FOP and FO Designer about the new font.

                                 

                              5.  Now in the FO Designer select the field that will contain arabic text and select the TraditionalArabic font:



                              6. As a final step, in the XPath of the field you have to add the function j4lext:toArabic() that takes care of reversing the text (for right to left writting) and adding the correct ligatures



                              7. If you now execute your report, the PDF file will contain the correct text.