1

I'm trying to render text with dompdf. It should look exactly like in the browser. That works, as long as the characters of the words are not formatted:

With HTML like:

<span style="color: #000000; font-family:'opensans'">
    <p style="font-size: 30.57465524239px;">
        This Text is a test to show the different behaviour!
    </p>
</span>

Browser text without formats

enter image description here

dompdf text without formats

enter image description here

But if I want to give the characters different styles, with HTML like:

<span style="color: #000000; font-family:'opensans'">
    <p style="font-size: 30px;">
        This Text is a test to 
        <span style="color: #800080;">s</span>
        <span style="color: #ff0000;">h</span>
        <span style="color: #000080;">o</span>
        <span style="color: #003300;">w</span>  
        <span style="color: #000080;">t</span>
        <span style="color: #ff00ff;">h</span>
        <span style="color: #ff0000;">e
            <span style="color: #000000;">different behaviour!</span>
        </span>
    </p>
</span>

The browser still displays it like intended:

enter image description here

But dompdf displays it like word-break: break-all; would be active.

enter image description here

I have already tried to add word-break: keep-all; to the surrounding <span> or <p>. I have also tried to surround the words with another <span> or <nobr> element, but that didn't change anything.

So, my question is, how can I get dompdf to keep the normal word-break rules on words with formatted characters?

4

1 回答 1

0

现在我已经解决了一个 PHP 函数,它使用 dompdf 来测量格式化的 textwidth 并<br>在我需要的地方添加必要的内容。

这不是最好的解决方案,我希望有人会找到更好的解决方案。但是现在它对我有用,我会在这里发布,也许它会对某人有所帮助。

PHP dompdf wrapText

它采用以下形式的 HTML 代码:

<span style="color: #000000; font-family:'opensans'">
    <p style="font-size: 30.57465524239px;">
        This Text is a test to show the different behaviour!
    </p>
</span>

并以以下形式返回 HTML 代码:

<span style="color: #000000; font-family: opensans; font-weight: normal; font-size: 30.57px;">T</span>
<span style="color: #000000; font-family: opensans; font-weight: normal; font-size: 30.57px;">h</span>
...
<span style="color: #000000; font-family: opensans; font-weight: normal; font-size: 30.57px;">t</span>
<br>
<span style="color: #000000; font-family: opensans; font-weight: normal; font-size: 30.57px;">t</span>
...

它对我来说非常可靠,因为我的输入文本总是完全一样的。

它从内联样式标签和周围的粗体信息中获取最多的样式信息<strong>

于 2016-04-13T15:12:06.113 回答