dompdf icon indicating copy to clipboard operation
dompdf copied to clipboard

CSS and Images no longer working

Open Roxeen12 opened this issue 1 year ago • 7 comments

Hi there!

I'm using this package with laravel modules and the CSS and the external images are no longer working.

Everything works on my local environment as it should, but on the server, the style is no longer applied in the PDF.

This is how i am importing the CSS:

{{ module_vite('build-eventpage', 'resources/assets/sass/app.scss') }}

and this is how i am using the images:

<img src="https://images.domain.com/domain-logo-orange.svg" alt="logo" class="logo__image">

It's weird because on my staging server the CSS is working but the images are not, and on the production nothing is working anymore.

Is something blocking the images to be rendered and the CSS to be applied?

Thank you!

Production: CleanShot 2024-09-13 at 12 54 12@2x

Staging: CleanShot 2024-09-13 at 12 55 06@2x

Local: CleanShot 2024-09-13 at 12 55 29@2x

Roxeen12 avatar Sep 13 '24 11:09 Roxeen12

How are you loading your document into Dompdf? Are paths correct for local vs production systems? Are remote resources allowed via your configuration?

I don't use laravel but it looks like the DEV URLs generated by vite may differ from the production URLs.

bsweeney avatar Sep 13 '24 11:09 bsweeney

Hi @bsweeney! Sorry for the miscommunication, i am using laravel-dompdf, which is a wrapper of this package.

Roxeen12 avatar Sep 13 '24 11:09 Roxeen12

I understand you're using laravel-dompdf, I just don't have a test environment where I can check things since I do not use laravel. My questions are still relevant, particularly with regard to vite. If you're using a DEV configuration locally that may be the reason it's rendering as expected in that environment.

bsweeney avatar Sep 13 '24 13:09 bsweeney

https://github.com/barryvdh/laravel-dompdf/issues/1065#issuecomment-2349025060 https://github.com/barryvdh/laravel-dompdf/issues/1059#issuecomment-2218671789 https://github.com/barryvdh/laravel-dompdf/issues/1058#issuecomment-2271127007

parallels999 avatar Sep 17 '24 17:09 parallels999

images and css stopped working for me as well - but only if request contains https. Requested with http they still work.

maschenborn avatar Sep 19 '24 07:09 maschenborn

@maschenborn you might try enabling additional debug messaging to see if something helpful is surfaced.

bsweeney avatar Sep 19 '24 14:09 bsweeney

$pdf->setOption(['isRemoteEnabled' => true]); is work for me

techtuneitbackenddev avatar Sep 30 '24 10:09 techtuneitbackenddev

Images are not loading for me. I've tried setting static image tag urls to proven paths both http and https and nothing works. I'm not using a wrapper, just this repo and so far everything else in the PDF renders fine except for images. Even background images in CSS do not render.

    public function getPDF() {
        $dompdf = new Dompdf();
        $html = '<img src="https://images.ctfassets.net/kugm9fp9ib18/YDOlzAWkee9uqayk46Fzs/c155ab88030301a5fd2b6f15e7064749/steak-n-feta-pita_20231120_web.jpg" />';
        $dompdf->loadHtml($html);
        $dompdf->render();
        $filename = $this->PlanName . '.pdf';
        $dompdf->stream($filename, array('Attachment' => 0));
        return $dompdf;
    }

clintLandrum avatar Jan 02 '25 17:01 clintLandrum

@clintLandrum would need to see a sample of what you tried plus the Dompdf options you specified.

bsweeney avatar Jan 02 '25 21:01 bsweeney