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


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.

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

      @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;
      border: none;
        font-family: 'Montserrat', sans-serif;
        font-family: 'Montserrat', sans-serif;

        position: absolute;
        right: 0;
        top: 0;
        height: 80px;
        width: 80px;



{% for product in products %}
          <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 %}

Part of controller where print pdf function is called:


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->setPaper('A4', 'portrait');
        $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');
How to&Answers: