打印 25 页 pdf 时 dompdf 超时

dompdf timeout when printing 25 page pdf

我在生成 dompdf pdf 时遇到问题。它呈现正确,但是当我尝试制作一个 25 页的 pdf 文件时,出现 php 超时 30 秒错误。

我正在通过正确设置 imgpaths 的 domelement 制作 pdf。此外,它将一个值设置为 2 个字段。

我查了一下,发现如果解析了新的正文元素,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 &ldquo;Krieghuusbelten&rdquo;</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">&nbsp;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&ouml;nnen Sie mit dem drahlosen Netzwerk verbindung machen.
            </li>
            <li>
              Starten Sie internet. Sie bekommen den Aktivierungsseite.
            </li>
            <li>
              Geben Sie den oben erw&auml;hnten Aktivierungscode ein. Die Dauerder Anwenung startet nach den Aktivierung.
            </li>
            <li>
              Sie k&ouml;nnen jetzt das Internet benutzen.
            </li>
            <li>
              <b>Achtung!</b> Dieser code k&ouml;nnen sie gleichzeitig aktiveren f&uuml;r den Einsatz auf 1 Ger&auml;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 &ecirc;tes dans les environs d&rsquo;un point d&rsquo;acc&egrave;s Wifi, vous serez
              <br />reli&eacute;s apr&egrave;s quelques secondes automatique au r&eacute;sea Wifi systeme sans fil.
            </li>
            <li>
              D&eacute;marrez internet. Alors sur le site du hotel ou camping.
            </li>
            <li>
              Compl&eacute;tez le code d&rsquo;acc&egrave;s mentionn&eacute; ci-dessus. La dur&eacute;e d&rsquo;utilisation commence apr&egrave;s l&rsquo;activation.
            </li>
            <li>
              Vous pourrez maintenant utiliser internet.
            </li>
            <li>
              <b>Attention!</b> Ce code est utilis&eacute; sur 1 p&egrave;riph&egrave;rique
            </li>
          </ul>
        </div>
      </div>
    </div>
  </div>
</body>

任何人都可以帮我让它加载得更快吗?我们将不胜感激。

事实证明,这是我工作的计算机。我的家用电脑在 +/- 15 秒内生成 pdf。