1

Codeigniter を DomPDF で使用しており、通常は問題なく動作しますが、空白ページを挿入したり、後続のコンテンツをカットしたりする場合があります。これは、連続したタグを含むテキストのチャンク内に<i>またはタグがある場合に発生することに気付きました。たとえば、次の構造を取ります。<b><br />

<p>some text <i>some text<br /><br />some text ... </i></p>

空白のページを挿入し、コンテンツを切り取ってしまいます。

コンテンツを出力するコードは次のとおりです。

...
<div style="page-break-before:always;"></div>

<?php foreach ($entries as $entry) { ?>

    <p><?php echo nl2br(str_replace("  ", "&nbsp;&nbsp;", $entry['description'])); ?></p>   

<?php } ?>

<p><?php echo $copyrightmessage ?></p>

<div style="page-break-before:always;width:100%;text-align:center;">

    <div style="height:100px;"></div>

    <img src="writerbig.png" />
    <br />
</div>
...

問題を再現するためのサンプル HTML を次に示します。

To better understand why this course of action was necessary, 
A'th'n learned why<br /> <br /> it was the responsibility, shame of each of the incarnations for ridding this 
world of<br /> <br /> this threat.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; H'br'a, spoken 
through A'yd'a, explained the CHTHONIAN collective and why, since<br /> <br /> A'yd'a through T'li'a, H'br'a, now, A'th'n it had to come to this point.<br /> <br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<i>Since her initial landfall, every time that the Primae had released a life force<br /> <br /> from a body she 
killed, this being the only logical solution to correct the crisis,<br /> <br /> the spirit had nowhere to go. <br /> 
<br /> It hung in the ether seeking spiritual release. Never finding any, the spirits soon <br /> <br /> learned that 
joining together made them capable of<br /> <br /> creating entities that could exist, again, in the living world, 
albeit as Sapen<br /> <br /> mockeries. <br /> <br /> Learning swiftly, the collected spirits came to the 
realization that not<br /> <br /> only could they exist on the living plane they could alter it.<br /> <br /> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; It was this "awakening" that started their raiding, terrorizing, 
destroying all<br /> <br /> living beings they encountered.<br /> <br /> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The end result of their intermingling was to, first, confuse, next, 
annihilate<br /> <br /> the outer husks of the tortured to absorb them into their collective existence.<br /> <br 
/> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In time, the first few spirits realized they were capable of 
manipulation,<br /> <br /> allowing them to become very adept at their methods with the one goal being 
total<br /> <br /> domination of all species, races.<br /> <br /> Keeping their combined numbers small enabled 
them to become the most powerful psychic <br /> <br /> entities ever created.<br /> <br /> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; The more powerful, the collective became the more notice the 
Primae took of them.<br /> <br /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Within a few life cycles, the 
Primae realized it was her responsibility to end<br /> <br /> this threat. However, the collective was always one 
step ahead, they knew that if the<br /> <br /> Primae caught them, she would release them back, unwillingly, 
into the spirit world<br /> <br /> where they would soon disperse into eternity.<br /> <br /> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; This evasion continued until H'br'a, who was a greater Primae then 
ever before,<br /> <br /> since she was a hybrid of two species, Sapen and Floar. It was this species melding<br 
/> <br /> that prevented the collective from manipulating her mind.<br /> <br /> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; H'br'a would have succeeded, in totally eradicating the collective 
that all the<br /> <br /> previous incarnations had attempted, except two had been on a raid, when she 
arrived.<br /> <br /> Before H'br'a had the opportunity to complete the spiritual release, she had<br /> <br /> 
received her next to last tattoo that triggered her action to seek out her successor.<br /> <br /> All following 
actions lead to her capture by the Levians until she was rescued<br /> <br /> and reborn as A'th'n.<br /> <br /> 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Now it was up to A'th'n, a further enhanced incarnation, who, 
because of&nbsp;&nbsp;her<br /> <br /> being an older Primae incarnation and her physical differences, made 
her immune to the<br /> <br /> CHTHONIAN collective influence.<br /> <br /> Her untried plan with F'lisa, 
hopefully, would be the solution.</i><br /><br /><br />

各エントリには、オプションでいくつかのタグ<i><b>タグを除いてプレーン テキストが含まれます (適切にネストされます)。エントリからタグを削除すると、<i>完全にフォーマットされます。

これを回避する方法はありますか?

4

2 に答える 2

2

PDFファイルを印刷する前に、HTMLのネストを解除するスクリプトを作成することになりました。

私は次のようなことをしました:

<br />タグ間のすべてのタグを見つけて<i></i>、それらを次のように置き換えます</i><br /><i>

ネストされた HTML タグの任意の組み合わせが可能である場合、このアプローチは十分に拡張できないことはわかっていますが、私の場合、タグは , に限定されていました<br><i><b>

うまくいけば、これは誰かに役立つでしょう

于 2013-07-12T18:37:26.237 に答える