DomPDF Image not found or type unknown

Viewed 749

Technologies used:

PHP: v7.4
SilverStripe: v4.7
DomPDF: 1.0

Composer

Before posting this, I made sure that I was able to follow the other tips and articles that are related to this DomPDF not showing the included image, but the image still ins't working

Image not found

Code-wise, I have already enabled the setIsRemoteEnabled option for the DomPDF, as per some of the devs mentioned in the github page

Classes

DomPDF Options

Here's the endpoint 1/2
Endpoint

Endpoint 2/2
Endpoint 2

Here's the Invoice generator
FE

Looking at the generated invoice, I was able to display the path of the image, and when I click to it, it's being displayed properly
Image

Image 2

It's just that the image isn't working for DomPDF, did I miss anything or is there a wrong code in my codebase? Would be very grateful for your help, been stuck for 4 days now

1 Answers

I was able to finally get a technique!

enter image description here

Instead of adding the file path, just convert your images into Base64, worked like a charm!

enter image description here

Here's the code snippet for an easy copy paste

// Get Base64 of the Logo
$path = Director::baseFolder() .'/public'.$config->WebsiteLogo()->getURL();
$type = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$logo = 'data:image/' . $type . ';base64,' . base64_encode($data);
Related