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

一世执手 提交于 2021-01-01 00:02:52

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/62589441/is-there-any-way-to-start-my-arabic-text-from-right-to-left-when-export-as-pdf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!