Camron Cade

Artisan web development, mostly using Laravel.

Things to note when using Dompdf

While using Dompdf for a project I came across two small things that are worth noting.

Dompdf is a PHP package that converts html/css markup into a PDF. It's not super stable and can be gimmicky at times, but it works.

1. Image widths

After struggling to get Dompdf to respond to CSS, inline, or external styles to set the width of an image I did some Googling. Apparently this is a common issue.

What did work for me was using max-width: instead of the good 'ol width:. If you're having this same issue and are unable to get Dompdf to resize your image, try this out.

2. Loading in foreign assets and images

You'll know this isn't working because you'll get a message that says "Image not found or type unknown" if it's an image, or your stylesheet won't load.

If you load any stylesheets, images, or other assets that are not hosted locally, you need to setup one setting before you go using it.

Here's the code:

$options = new \Dompdf\Options();
$options->set('isRemoteEnabled', true);
$dompdf = new \Dompdf\Dompdf($options);

// Whatever you want to use $dompdf for