← More Guides

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]);

Unlock all the notes for $4

No subscriptions, no auto-renewals.

Just a simple one-time payment that helps support my free, to-the-point videos without sponsered ads.

Unlocking gets you access to the notes for this video plus all 200+ guides on this site.

Your support is appreciated. Thank you!

Payment Info

/
$4 6 months
$25 forever
Please check the form for errors
Questions? help@codewithsusan.com
← More Guides