PHP在第二个pdf文件页面图像消失中生成pdf

问题描述 投票:0回答:1

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

例如,您可以转到我的网站将产品添加到购物车,然后转到您的购物车并打印购物车。https://e-gilius.com/index.php?route=checkout/cart

我应该检查什么?代码很大,所以我不知道要包括哪一部分,所以这是我的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>

称为打印pdf功能的控制器部分:

<?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;
  }
php dompdf
1个回答
0
投票

[尝试手动拆分PDF,假设您可以在一个A4页面上放置10种产品

<style>
    .break {
        page-break-after: always;
    }
</style>
<table>
    <tr>
        <th>&nbsp:</th><th>Name</th><th>Quantity</th><th>Price</th>
    </tr>
</table>
{% for row in products|batch(10) %}
    {% for product in row %}
<table>
    <tr>
        <td>{% if product.thumb %} <a href="{{ product.href }}"><img src="{{ product.thumb }}" alt="{{ product.name }}" title="{{ product.name }}" class="img-thumbnail" /></a>{% endif %}</td>
        <td>{{ product.name }}</td>
        <td>{{ product.quantity }}</td>
        <td>{{ product.price }}</td>
    </tr>
</table>
<div class="break"></div>
    {% endfor %}
{% endfor %}
© www.soinside.com 2019 - 2024. All rights reserved.