如何在 HTML 中对齐文本?(Netsuite 高级 PDF)

How to Justify text in HTML?(Netsuite AdvancedPDF)

我正在用阿拉伯语创建高级 PDF。它是一种只有阿拉伯文字的字母。它没有得到证明。我尝试在 <td><span> 中使用 style="text-align: justify; text-justify: inter-word;",但仍然没有用。

谁能告诉我是否可以证明阿拉伯语是正确的? 我的脚本块:

<?xml version="1.0"?>
<!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<!-- <pdf dir="rtl" lang="ar"> -->
<pdf>

  <head>
    <!-- arabic Font -->
    <link name="majalla" type="font" subtype="opentype"
      src="https://5486702.app.netsuite.com/core/media/media.nl?id=8627&amp;c=5486702&amp;h=3e47c429eda24f454f39&amp;_xt=.ttf"
      bytes="6" />
    <style type="text/css">
      body {
        font-family: majalla;
        font-size: 18pt;
      }
    </style>
  </head>

  <body font-famly="ariel" header="nlheader" header-height="14%" footer="nlfooter" footer-height="20pt"
    padding="0.5in 0.7in 0.5in 0.7in" size="Letter">
    <table width="100%" table-layout="fixed">
      <tr margin-top="10px">
        <td align="right" lang="Ar">
          <#if record.custbody7?has_content>
            <p align="right"><span align="right" style="text-align: justify; text-justify: inter-word;">${record.custbody7}</span>
              <#else>
                <p align="right" style="text-indent: 35px;"><span align="right">أفيدكم بأنه لا مانع لدينا من قيامكم
                    بتنفيذ المشروع أعلاه وذلك لمدة </span>
                  <span align="right" style="text-align: justify; text-justify: inter-word;">(
                    ${record.custbody_duration?string?replace('0','٠')?replace('1','١')?replace('2','٢')?replace('3','٣')?replace('4','٤')?replace('5','٥')?replace('6','٦')?replace('7','٧')?replace('8','٨')?replace('9','٩')}
                    )</span> <!-- duration -->
                  <span align="right" style="text-align: justify; text-justify: inter-word;"> تبدأ من تاريخ </span>
                  <span align="right" style="text-align: justify; text-justify: inter-word;">${record.custbody_start_date?string?replace('0','٠')?replace('1','١')?replace('2','٢')?replace('3','٣')?replace('4','٤')?replace('5','٥')?replace('6','٦')?replace('7','٧')?replace('8','٨')?replace('9','٩')}
                    م ، </span> <!-- start date -->
          </#if>
          <span align="right" style="text-align: justify; text-justify: inter-word;">ومن ثم ترفع المطالبات للإدارة المالية بتقديم جميع المستندات المؤيدة للصرف علًما بأن أصل
            هذا التعميد لدى الإدارة المالية في مكتب برنامج خدمة ضيوف الرحمن. </span>
          </p>
        </td>
      </tr>
    </table>
  </body>
</pdf>

在几个地方您正在使用 <span align="right">。这里存在三个问题:

1.) span 是一个内联元素——在内联元素中使用文本对齐是没有用的。使用 div 而不是 span。那是一个块元素,它的默认宽度是它父元素的全宽,所以文本对齐会有影响。

2.) align="right" 不是有效的 HTML 属性。如果你想直接将对齐添加到像 div 这样的元素,你必须使用 <div style="text-align: right;">。或者(更好)您将 class 应用于 DIV 并为包含所需文本对齐的 class 设置 CSS 规则。如果您希望您的文本对齐,请改用 <div style="text-align: justify;">

3.) 对于从右向左书写的语言,你不仅要使用右对齐,还要添加文本方向参数,如direction: rtl; ("right to left"),所以加起来<div style="text-align: justify; direction: rtl;">,或者(更好)class 的 CSS 规则,其中包含您应用于 HTML 标签的那些设置。