Open elessa237 opened 2 years ago
This is only a wrapper, dompdf package it not here
we can work around this situation if we use base64 images.
Most likely it is not the issue with the package but the problem in your dev environment.
I assume it happens because your local environment fails to verify the SSL certificate (at least that happened to me). If you turn on the 'show_warnings' flag in your dompdf configuration file you will see the actual error. And if you get the same error as below you need to create your own root certificate.
file_get_contents(): SSL operation failed with code 1.
In my case, I am using MAMP so I followed instructions that I found on stack overflow and it worked as a charm.
I strongly suggest fixing this problem instead of using base64 images as a workaround.
Try adding this on config/dompdf.php
'options' =>[
///
'http_context' => [
'ssl'=>[
'verify_peer'=>false,
'verify_peer_name'=>false,
'allow_self_signed'=>true
]
],
Source: dompdf/Options.php#L408-L410
@elessa237 I ran into the same issue now and I found out that the reason for this was because the package could not access the image on my local machine. A quick walk-around is to upload the image to some online server and use that link instead (at least for test purposes).
Using setWarnings(true)
allows you see what the issue might be.
Pdf::loadView('view-name')
->setPaper('a2', 'portrait')
->setWarnings(true)
->save($filePath);
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Any issues with PDF rendering itself that are not directly related to this package, should be reported on https://github.com/dompdf/dompdf instead. When having doubts, please try to reproduce the issue with just dompdf. If you believe this is an actual issue with the latest version of laravel-dompdf, please reply to this issue so we can investigate further. Thank you for your contribution! Apologies for any delayed response on our side.
To solve my problem, I simply used an absolute URL and it works very well. <img src="{{ absolute_url(asset('images/aris_logo.png')) }}" style="height: 50px; width: 100px;" alt=""/>. I would like to remind you that I am using Symfony, so I'm using Twig templates.
we can work around this situation if we use base64 images.
Merci pour cette reponse :
$imageData = base64_encode(file_get_contents('images/lgg.png'));
we can work around this situation if we use base64 images.
Merci pour cette reponse :
$imageData = base64_encode(file_get_contents('images/lgg.png'));
Working 100%!
I use dompdf version 2.0 and symfony 5.4.
when rendering the pdf I have an error while displaying the image "image not found or type unknown".
my dompdf code
`<?php
namespace App\Infrastructure\Prints;
use Dompdf\Dompdf; use Dompdf\Options;
/**
@package App\Infrastructure\Prints */ class PrintService { public function print(string $html, string $name, string $orientation = 'portrait', string $format = 'A5'): void { $options = new Options(); $options->setIsRemoteEnabled(true); $options->setIsHtml5ParserEnabled(true); $options->set('defaultFont', 'Courier');
} }`
my img tag in my vu twig
`
`
l'image se trouve dans /public