为什么我的 DomPDF 无法渲染 HTML 中的图像?

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

我正在 PDFGeneratorService 中制作 PDF,除了图像未渲染外,一切正常。我已经将图像更改为jpeg格式,我已经添加了chroot,我已经添加了

'dompdf' =>[
        'enable_remote' =>true,
    ],

我的应用程序配置 但似乎没有任何东西可以渲染图像:

<img src="{{ asset('logo/Logo.jpg') }}" alt="" class="">
,这是代码

namespace App\Services;

use Dompdf\Dompdf;
use Dompdf\Options;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;

class PDFGeneratorService

{

    protected $dompdf;

    public function __construct(){
        $this->dompdf = new Dompdf();
    }
    public function generateReceiptPDF($receipt){
        $options = new Options();
        $options->set('default', 'Arial');
        $options->set('isPhpEnabled', true);
        $options->setChroot("/public/assets");
        $this->dompdf->setOptions($options);
        $this->dompdf->setPaper('A4', 'landscape');
        $html = view('pdf.receipt', ['receipt' => $receipt]);
        $this->dompdf->loadHtml($html);
        $this->dompdf->render();
        $directory = public_path('storage/temp');
        
        $filename = 'receipt_' . $receipt->created_at->format('YmdHis') . '.pdf';
        File::ensureDirectoryExists($directory);
       
        $pdfPath = Str::finish($directory, '/') . ltrim($filename);
      
        
        file_put_contents($pdfPath, $this->dompdf->output());
        return $pdfPath;
    }
}```
Please help, thanks in advance!
php dompdf
1个回答
0
投票

将图像转换为 Base64 字符串,然后将其放入

src
标签的
img
中。

DOM PDF 不允许直接渲染图像。

© www.soinside.com 2019 - 2024. All rights reserved.