2013-07-04 19 views
1

我使用的是與DomPDF一起使用的Codeigniter,它通常運行良好,但有時會插入空白頁面並剪切後面的內容。我注意到,這發生在<i><b>標籤中包含連續<br />標籤的文本塊。例如,採取以下結構:爲什麼DomPDF插入一個空白頁面並剪切內容

<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>標籤,它的格式完美。

任何想法如何解決這個問題?

+0

這將有助於查看HTML,而不是生成HTML的PHP​​。我無法用您發佈的簡單代碼複製問題。另外,你使用的是哪個版本的dompdf? – BrianS

+0

嗨@BrianS,我編輯了這個問題來添加實際上打破的HTML。請讓我知道,如果你能重現這個問題。我正在使用最新版本(剛剛從GitHub下載了它) –

+0

我不確定問題出在哪裏,但dompdf肯定遇到了這個問題,可能是一個關於celements和分頁的問題,我真的沒有什麼好的解決方案現在除了將每一行隔離到它自己的DIV元素中 – BrianS

回答

2

我最終編寫了一個腳本來在打印PDF文件之前解除嵌套HTML。

我不喜歡的東西:

找到<i></i>標籤之間的所有<br />標籤與</i><br /><i>

我知道,這種方法將不能很好地給予,如果嵌套的HTML標記的任意組合是可能取代他們,但在我的情況下,標籤被限制爲<br><i><b>

希望這將有助於有人

0

嵌套標籤和DomPDF不是好朋友。你可以嘗試使用字體,如果這不起作用,請嘗試用跨度替換它們。

也許問題出在一些分頁符。如果標籤打開時頁面中斷,則會打破整個PDF。

+0

這不一定是正確的dompdf能夠很好地處理嵌套標籤有些問題可能有問題但我不認爲「嵌套標籤」是問題在這裏。 – BrianS

相關問題