← Other topics

dompdf - View PDF in browser instead of downloading

Video Notes

When using the package dompdf/dompdf an issue I faced was despite using the stream method, my PDFs were always being downloaded instead of displaying directly in the browser.

To fix this, replace:

$dompdf->stream();

With:

$dompdf->stream("", ["Attachment" => false]);

Full code example:

<?php

require 'vendor/autoload.php';

use Dompdf\Dompdf;

$dompdf = new Dompdf();
$dompdf->loadHtml('<h1>hello world</h1>');
$dompdf->render();

# Before 😔
#$dompdf->stream();

# After 😀
$dompdf->stream("", ["Attachment" => false]);

If this info helped you out you can say thanks and support future content by clicking my Amazon affiliate link: https://amzn.to/3UtgnYk. If you make a purchase on Amazon within 24 hours of clicking the link I may receive a micro-commission and it costs you nothing extra. Any income from these sales goes directly to supporting me in making new videos and guides. Thank you for your support!

← Other topics