DOMPDF: Image not found or type unknown

If you are using DOMPDF on a server environment that has a self-signed security certificate, or perhaps the certificate name doesn’t match what it should, DOMPDF will not load images or other assets without specifically creating a stream context that allows it to do so.

// DOMPDF version 0.7.0
use Dompdf\Dompdf;
use Dompdf\Options;
require_once 'dompdf/autoload.inc.php';
$options = new Options();
$options->set('isRemoteEnabled', TRUE);
$dompdf = new Dompdf($options);
$contxt = stream_context_create([ 
	'ssl' => [ 
		'verify_peer' => FALSE, 
		'verify_peer_name' => FALSE,
		'allow_self_signed'=> TRUE 
	] 
]);
$dompdf->setHttpContext($contxt);
// ...

For me this problem happened on the development environment (Ubuntu 16.04). I didn’t try it on the production environment, but it would have been fine there, because it has a valid security certificate.

Posted May 25th, 2016 in

Reader Comments (2)

Mailson

Thanks, you saved me!

Lucas

Thank you so much !!!

Leave a comment