0 0 votes
Article Rating

It seems like you’re providing additional information and a solution for the issue where DOMPDF images are not showing in a PHP script, particularly when trying to load remote URLs. If that’s the case, here’s an example of how you can enable remote URLs in DOMPDF:

#image_title

// Include DOMPDF library
require ‘vendor/autoload.php’; // Adjust the path based on your project structure

use Dompdf\Dompdf;
use Dompdf\Options;

// Initialize DOMPDF
$options = new Options();
$options->set(‘isHtml5ParserEnabled’, true);
$options->set(‘isPhpEnabled’, true);

// Enable remote URLs
$options->set(‘isRemoteEnabled’, true);

$dompdf = new Dompdf($options);

// Your HTML content with remote image URL
$html = ‘<html><body><img src=”https://example.com/your-image.jpg” alt=”Image”></body></html>’;

// Load HTML content
$dompdf->loadHtml($html);

// Set paper size (optional)
$dompdf->setPaper(‘A4’, ‘portrait’);

// Render PDF (output to browser or save to file)
$dompdf->render();

// Output the generated PDF
$dompdf->stream(‘output.pdf’, array(‘Attachment’ => 0));

In this example, the key part is setting the ‘isRemoteEnabled’ option to true, which allows DOMPDF to fetch and include images from remote URLs. Adjust the HTML content with your actual remote image URL.

Make sure you’ve updated to the latest version of DOMPDF from the GitHub repository to ensure that you have the most recent bug fixes and improvements.

Remember to adjust the path to the autoload file based on your project structure.

0 0 votes
Article Rating
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments