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.
- 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
- execute the tools/createFontMetrics.bat to create the output
file trado.xml
- edit trado.xml and make sure both the <font-name> and the
<family-name> tags contain the value TraditionalArabic
- 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.
- Now in the FO Designer select the field that will contain arabic
text and select the TraditionalArabic font:
- 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
- If you now execute your report, the PDF file will contain the correct
text.
|