如何在 html2pdf 的同一行中显示阿拉伯文和英文文本

How to show arabic and english text in same line in html2pdf

我需要像那样使用 html2pdf 以 pdf 格式编写表格文本

<div><span> - English Translation 1 :   </span><span> :      Arabic Translation 1</span></div> 
<div><span> - English Translation 2:   </span><span> :      Arabic Translation 2</span></div> 
<div><span> - English Translation 3:   </span><span> :      Arabic Translation 3</span></div> 

我从 https://github.com/iafan/html2pdf/blob/master/_tcpdf_5.9.206/examples/example_018.php 那里得到了一个例子,但这似乎适用于分页页面。

到目前为止我做了以下代码。

$finder = new Zend_Dom_Query($htmlContent);
$classname = "intl-text";
$nodes = $finder->query("*[class~=\"$classname\"]");

foreach($nodes as $node) {
    foreach($features as $feature) {
        $engText = $feature->getEnglishText();
        $arbText = $feature->getArabicText();

        $div = $dom->createElement("div");

        $span = $dom->createElement("span");
        $span->nodeValue = "- ".$engText;
        $div->appendChild($span);
        $span = $dom->createElement("span");
        $span->setAttribute("style", "direction: rtl;");
        //$span->setAttribute("dir", "rtl");
        $span->nodeValue = ":   ".$arbText;
        $div->appendChild($span);

        //$div->nodeValue = "- ".$engText.":   ".$arbText;

        $node->appendChild($div);
    }
}   

$content = $nodes->getDocument()->saveHTML();

$html2pdf->writeHTML($content, false);
$html2pdf->Output(__DIR__.'Output.pdf', 'F');

经过更多搜索,我通过以下更改得到修复。

$span->setAttribute("style", "direction: rtl;display: inline-block;font-family:dejavusanscondensed;");

css 中的字体家族成功了,文本现在以阿拉伯语显示在 pdf 中。但是它不是右对齐的。但我怀疑这可能需要一些 html 修复。

发件人:Indian currency symbol not show when convert html2pdf in php .