dongliuliu0385 2015-04-17 08:55
浏览 70
已采纳

打印25页pdf时dompdf超时

I have a problem generating my dompdf pdf. It renders correctly, but when i try to make a 25 page pdf file the php timout 30 seconds error occurs.

I am making the pdf via a domelement that sets the imgpaths correctly. Also, it sets a value to 2 fields.

I looked it up and it turned out that dompdf makes a new page if a new body element was parsed. So i am inserting multiple body's for multiple pages. It renders fine, it just takes very long so i am probably doing something wrong.

My pdf generation code is as follows:

    $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);

The HTML is as follows:

<!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>

Can anyone help me make it load a lot faster? all help will be appreciated.

</div>
  • 写回答

1条回答 默认 最新

  • dsdf64562672 2015-04-20 09:12
    关注

    As it turned out, it is the computer on which i work. My home computer generates the pdf in +/- 15 seconds.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题