我在生成dompdf pdf时遇到问题。它渲染正确,但是当我尝试制作25页的pdf文件时,发生了php timout 30秒错误。
我通过正确设置imgpaths的domelement制作pdf。此外,它将值设置为2个字段。
我查了一下,结果发现,如果解析了一个新的body元素,dompdf会生成一个新页面。所以我为多个页面插入了多个正文。它渲染得很好,只需要很长时间,所以我可能做错了。
我的pdf生成代码如下:
$pdf = Yii::app()->pfPDF->firstrun();
$basepath = str_replace('\\', '/', Yii::app()->theme->basePath);
$doc = new DOMDocument();
$doc->preserveWhiteSpace = false;
$htmlfile = $basepath.'/pdf/pdf.html';
$html = null;
\timestuff::$times[] = microtime(true);
foreach($models as $model)
{
$model->printed = true;
$model->save();
$doc->loadHTMLFile($htmlfile);
$html .= '<head>';
$headNode = $doc->getElementsByTagName('head')->item(0);
foreach($headNode->childNodes as $childnode){
if($childnode->nodeType == XML_TEXT_NODE){
continue;
}
$html.= $doc->saveHTML($childnode);
}
$html .= '</head><body>';
$doc->getElementById('vouchercode')->nodeValue = $model->code;
$doc->getElementById('timelimit')->nodeValue = $timelimit;
$doc->getElementById('nllogo')->attributes->getNamedItem('src')->nodeValue = $basepath.'/pdf/assets/images/plate.png';
$doc->getElementById('enlogo')->attributes->getNamedItem('src')->nodeValue = $basepath.'/pdf/assets/images/plate.png';
$doc->getElementById('delogo')->attributes->getNamedItem('src')->nodeValue = $basepath.'/pdf/assets/images/plate.png';
$doc->getElementById('frlogo')->attributes->getNamedItem('src')->nodeValue = $basepath.'/pdf/assets/images/plate.png';
$doc->getElementById('customerlogo')->attributes->getNamedItem('src')->nodeValue = $basepath.'/pdf/assets/images/logo_krieghuus.png';
$doc->getElementById('maxwifilogo')->attributes->getNamedItem('src')->nodeValue = $basepath.'/pdf/assets/images/maxwifi.png';
$bodyNode = $doc->getElementsByTagName('body')->item(0);
foreach($bodyNode->childNodes as $childnode){
if($childnode->nodeType == XML_TEXT_NODE){
continue;
}
$html.= $doc->saveHTML($childnode);
}
$html.= '</body>';
}
\timestuff::$times[] = microtime(true);
Yii::app()->pfPDF->show($html);
\timestuff::$times[] = microtime(true);
HTML如下:
<!doctype HTML>
<head>
<title>
voucher pdf
</title>
<style>
#wrapper {
width: 800px;
background-color: white;
}
#vouchercode {
font-weight: bolder;
}
.topsection {
position: absolute;
top: 0;
height: 400px;
left: 0;
}
#topleftsection {
position: absolute;
top: 0px;
left: 0px;
width: 400px;
height: 400px;
}
#topleftimg,
#topleftimg img {
max-width: 400px;
max-height: 285px;
}
#topleftimgdescr {
text-align: center;
font-weight: bold;
}
#toprightsection {
position: relative;
clear: none;
top: 0px;
left: 400px;
height: 400px;
}
.maxwifisection {
margin-left: 100px;
}
.maxwifihref {
margin-right: 550px;
text-align: center;
}
#wifisection {
position: relative;
top: 100px;
}
.instructionsection {
position: absolute;
top: 400px;
bottom: 0;
/*page-break-after: always;*/
}
#nl {
height: 130px;
}
.countrytext {
margin-top: -44px;
margin-left: 8px;
font-weight: bolder;
color: white;
font-size: 30px;
font-family: "Verdana", Arial, sans-serif;
}
.countrypng {
width: 60px;
}
.partial {
height: 140px;
}
.instruction {
position: relative;
top: -120px;
left: 60px;
font-size: 14px;
}
ul {
margin-top: 0px;
}
</style>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<div id="wrapper">
<div class="topsection">
<div id="topleftsection">
<div id="topleftimg">
<img id="customerlogo" src="./assets/images/logo.png" />
</div>
<div id="topleftimgdescr">Vakantiepark de “Krieghuusbelten”</div>
</div>
<div id="toprightsection">
<div class="maxwifisection">
<img id="maxwifilogo" src="./assets/images/maxwifi.png" />
<br />
<div class="maxwifihref"><a>www.maxCoax.nl</a>
</div>
</div>
<div id="wifisection">
<table>
<tr>
<th>Wifi activatiecode</th>
<th></th>
</tr>
<tr>
<td>Tijdsduur:</td>
<td id="timelimit"></td>
</tr>
<tr>
<td>Apparaten:</td>
<td>1</td>
</tr>
<tr>
<td>Activatiecode:</td>
<td id="vouchercode"></td>
</tr>
</table>
</div>
</div>
</div>
<div class="instructionsection">
<div class="partial">
<div class="countrypng">
<img id="nllogo" src="./assets/images/plate.png" />
<div class="countrytext">NL</div>
</div>
<div class="instruction">
<b>Instructies</b>
<ul>
<li>
Start uw notebook, PDA of PC. Wanneer u binnen het bereik van een wifi hotspot bent kunt u verbinding
<br />maken met het Wifi netwerk. Start internet en de activatiepagina opent.
</li>
<li>
Vul de hierboven vermelde toegangscode in.
</li>
<li>
De tijdsduurgebruik gaat in na activatie.
</li>
<li>
U kunt gebruik maken van internet.
</li>
<li>
<b>Let op!</b> Deze toegangscode is te activeren op 1 apparaat.
</li>
</ul>
</div>
</div>
<div class="partial">
<div class="countrypng">
<img id="enlogo" src="./assets/images/plate.png" />
<div class="countrytext">EN</div>
</div>
<div class="instruction">
<b>Instructions</b>
<ul>
<li>
Start up your notebook, PDA or PC. Please connect with the Wifi network if you are within range of a Wifi
<br />access point.
</li>
<li>
Log on to the internet. You will land on the activation page.
</li>
<li>
Enter the above mentioned access code. The duration of use starts after activation.
</li>
<li>
You are now ready to use internet.
</li>
<li>
<b>Attention!</b> This code is for use on 1 device
</li>
</ul>
</div>
</div>
<div class="partial">
<div class="countrypng">
<img id="delogo" src="./assets/images/plate.png" />
<div class="countrytext"> D</div>
</div>
<div class="instruction">
<b>Hinweise</b>
<ul>
<li>
Starten Sie Ihr Notebook, PDA oder Ihren PC. Wenn Sie sich innerhald der Reichweite eines Accespoints
<br />befinden, dan können Sie mit dem drahlosen Netzwerk verbindung machen.
</li>
<li>
Starten Sie internet. Sie bekommen den Aktivierungsseite.
</li>
<li>
Geben Sie den oben erwähnten Aktivierungscode ein. Die Dauerder Anwenung startet nach den Aktivierung.
</li>
<li>
Sie können jetzt das Internet benutzen.
</li>
<li>
<b>Achtung!</b> Dieser code können sie gleichzeitig aktiveren für den Einsatz auf 1 Gerät.
</li>
</ul>
</div>
</div>
<div class="partial">
<div class="countrypng">
<img id="frlogo" src="./assets/images/plate.png" />
<div class="countrytext">FR</div>
</div>
<div class="instruction">
<b>Instructions</b>
<ul>
<li>
Ouvrez Votre portable, PDA ou PC. Lorsque vous êtes dans les environs d’un point d’accès Wifi, vous serez
<br />reliés après quelques secondes automatique au résea Wifi systeme sans fil.
</li>
<li>
Démarrez internet. Alors sur le site du hotel ou camping.
</li>
<li>
Complétez le code d’accès mentionné ci-dessus. La durée d’utilisation commence après l’activation.
</li>
<li>
Vous pourrez maintenant utiliser internet.
</li>
<li>
<b>Attention!</b> Ce code est utilisé sur 1 pèriphèrique
</li>
</ul>
</div>
</div>
</div>
</div>
</body>
任何人都可以帮助我加快速度吗?所有的帮助将不胜感激。
答案 0 :(得分:0)
事实证明,它是我工作的计算机。我的家用电脑在+/- 15秒内生成pdf。