Home » Php » dompdf – PHP generates pdf in second pdf file page images dissapear

dompdf – PHP generates pdf in second pdf file page images dissapear

Posted by: admin February 25, 2020 Leave a comment

Questions:

In next page image dissapears, the url of image is correct

For example you can go to my website add products to cart, then go to your cart and print the cart.
https://e-gilius.com/index.php?route=checkout/cart

What should i check?
The code is huge so i don’t know which part to include, so here is my pdf.twig

 <style>
      @media print {
      @page {
          size: letter;
          margin: 5px;
      }
    }
    * {
      /*font-family: 'Open Sans', sans-serif !important;/*font-family:"DeJaVu Sans Mono",monospace;*/
      font-family: 'Montserrat', sans-serif;
      font-size: 12px;
    }
    .img-thumbnail{
      max-height:70px;
      max-width:100px;
      border: none;
    }
    #h5{
        font-size:12px;
        font-family: 'Montserrat', sans-serif;
    }
    h5{
        font-size:10px;
        font-family: 'Montserrat', sans-serif;
    }

    #logo{
        position: absolute;
        right: 0;
        top: 0;
        height: 80px;
        width: 80px;

    }

  </style>

{% for product in products %}
        <tr>
          <td style="height: auto;" class="text-center">{% if product.thumb %} <a href="{{ product.href }}"><img src="{{ product.thumb }}" alt="{{ product.name }}" title="{{ product.name }}" class="img-thumbnail" /></a> {% endif %}</td>

I have tried to break loop in index 4 but it does not take effect

{% if loop.index == 4 %}
            <div class="break"><h1>YES WE DID A PAGE BREAK  {{loop.index}}</h1> </div>
          {% endif %}
        </tr>

Part of controller where print pdf function is called:

<?php

use Dompdf\Dompdf;
use Dompdf\Options;
require_once DIR_SYSTEM.'library/dompdf/autoload.inc.php';

class ControllerWkPdfWkPdf extends Controller {

  public function print() {
    if(isset($this->request->get['print']) && $this->request->get['print']) {

      $filename = 'private_group_cart';
      $default_group_id = $this->config->get('module_wk_pdf_private_cg_id');
      if($this->customer->isLogged() && $this->customer->getGroupId() == $default_group_id) {
        $html = $this->getHtml();
      } else {
        $html = $this->getPrivateGroupHtml();
      }
    } else {
      $html = $this->getHtml();
      $filename = 'cart';
    }

    $options = new Options();
        $options->set('isRemoteEnabled', TRUE);
        $dompdf = new Dompdf($options);
        $dompdf->loadHtml($html);
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->render();
        $savepath = DIR_DOWNLOAD . $filename . '.pdf';

        file_put_contents($savepath, $dompdf->output());
        header("Content-Type: application/octet-stream");
        header("Content-Disposition: attachment; filename=" . urlencode($filename.'.pdf'));
        header("Content-Type: application/octet-stream");
        header("Content-Type: application/download");
        header("Content-Description: File Transfer");
        header('Content-Length: ' . filesize($savepath));
        header('Accept-Ranges: bytes');
        readfile($savepath);
        exit;
  }
How to&Answers: