is there any way to start my Arabic text from right to left when export as PDF

Viewed 586

I am using Apache FOP 2.2 to Export as PDF. I want my arabic text to start from right to left. If i give text alignment as Right all characters are going to right end of the screen which is causing alignment issue in my pdf.

Code:

<fo:block  font-size="2.5mm" font-weight="bold" text-align="left"  white-space="normal" margin="1.5mm"
 xsl:use-attribute-sets="CustomStyles-ar"> 
الآن لحضورHarishالمؤتمر
 </fo:block>

Arabic text should start from right to left instead it is starting from left to right:

Arabic text should start from right to left instead it is starting from left to right

2 Answers

In our templates we set the writing-mode and if you have bullet lists, you may also want to set the text-align. We have something like this in XSL based on a param passed in whether we are formatting Arabic or other languages that are not:

<fo:flow flow-name="xsl-region-body">
   <xsl:choose>
     <xsl:when test="$direction='rtl'">
        <xsl:attribute name="writing-mode">rl-tb</xsl:attribute>
        <xsl:attribute name="text-align">start</xsl:attribute>
        <xsl:attribute name="text-align-last">start</xsl:attribute>
        <fo:bidi-override unicode-bidi="embed" direction="rtl">
           <!-- content Arabic here -->
        </fo:bidi-override>
      </xsl:when>
      <xsl:otherwise>
           <!-- non RTL content -->
      </xsl:otherwise>
    </xsl:choose>
</fo:flow>

You should be able to even use such a thing at lower levels against blocks or block-containers or other structures to control a completely mixed document.

For instance, the following image shows this when applied to left/right tables cells to build English document on left and Arabic on right.

enter image description here

Begin your text with &rlm;. This is U+200F RIGHT-TO-LEFT MARK, which indicates to the text layout system that the following block of text is RTL.

If your rendering system does not support the &rlm; entity, it can also be written as &#8207;. It is part of HTML 4.0, but not every engine implements it.

If needed, there is an similar &lrm; to switch to left-to-right.

Related