barryvdh / laravel-dompdf

A DOMPDF Wrapper for Laravel
MIT License
6.66k stars 966 forks source link

image not found or type unknown #915

Open elessa237 opened 2 years ago

elessa237 commented 2 years ago

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;

/**

my img tag in my vu twig

`

`

l'image se trouve dans /public

PaolaRuby commented 2 years ago

This is only a wrapper, dompdf package it not here

WoneyBranga commented 1 year ago

we can work around this situation if we use base64 images.

Tadaz commented 1 year ago

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.

PaolaRuby commented 1 year ago

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

Emmarex commented 1 year ago

@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);
stale[bot] commented 1 year ago

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.

elessa237 commented 1 year ago

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.

florella-yannis commented 1 year ago

we can work around this situation if we use base64 images.

Merci pour cette reponse :

$imageData = base64_encode(file_get_contents('images/lgg.png'));

dansp89 commented 1 year ago

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%!