28

I generated a PDF using the dompdf library and used this:

$dompdf->stream('my.pdf',array('Attachment'=>0));

to force the browser to let the user view the PDF before downloading. But it's not working. A Google search isn't bringing up any answers either. Can anyone help?

Bindiya Patoliya
  • 2,726
  • 1
  • 16
  • 15
OJuice
  • 435
  • 2
  • 6
  • 11

3 Answers3

91

Try using the below code. Let me know are you create data from form or html file data.

$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));

exit(0);
Nithyanandhan M
  • 1,524
  • 1
  • 16
  • 26
  • 2
    Seems like you don't need `exit(0);`. With `$dompdf->stream("dompdf_out.pdf");` the file gets dowloaded. With `$dompdf->stream("dompdf_out.pdf", array("Attachment" => false));` the file gets shown in the browser. – David Jul 15 '20 at 08:06
  • 1
    Exit is important in stream. Just found this answer and it's working. Saved day, but spent 4 hours to find! – TheFoxLab Aug 26 '22 at 11:11
4

If someone still looking for answer and it's still not resolved, try installing and turning on the PDF Viewer / PDF JS extension in the browser.

After adding parameter array(“Attachment”=>0) or array(“Attachment”=>false) to the stream and still not working. It's because your browser doesn't have a pdf reader available/activated. Installing and activating browser extension like PDF Viewer / PDFJS will force the browser to read and review the pdf.

rozanfik
  • 56
  • 4
  • 1
    Please add some further explanation to your answer such that others can learn from it – Nico Haase May 18 '20 at 08:02
  • if parameter array(“Attachment”=>0) or array(“Attachment”=>false) isn't working it's because the pdf reader in the browser isn't available. PDFJS extension will force the browser to read and review the pdf. – rozanfik May 18 '20 at 08:46
0

Try this

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

Instead of

$dompdf->stream();

It worked for me

Syscall
  • 19,327
  • 10
  • 37
  • 52