0
votes

I am using Laravel 5.4 and using

"barryvdh/laravel-dompdf": "^0.8.0",

https://github.com/barryvdh/laravel-dompdf

i have follwoing code in controller

$pdf = PDF::loadView('print.print', $data);
return $pdf->download('invoice.pdf');

As it will download pdf properly but i am looking to preview the content in the view to print. i have googled lot still not able to get it

2
You can do a workaround for printing using JavaScript, - Abdelrahman M. Allam
is it possble to view pdf in new browser tab without downlaoding - scott
You can just use the ->stream() method? - Khoon
i ahve tried stream but its downlaoding not view - scott
You need to send the pdf to the new window then execute window.print() the browser will preview the pdf as print - Abdelrahman M. Allam

2 Answers

3
votes

You can use stream() function as stated in documentation here.

According to documentation of dompdf, When you use stream like this:

$dompdf->stream('filename.pdf');

In default, you will see a download dialouge box.

But, you can add parameter Attachment value to false so that you can view pdf in browser.

Here is what you need to do:

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

This might help you.

0
votes

I've struggled with this and manage to make it work with the following snippet:

$html = view('desktop.bill', $data)->render();
return @\PDF::loadHTML($html, 'utf-8')->stream(); // to debug + add the follosing headers in controller ( TOP LEVEL )

Besides the upper command, you will need to add on a TOP LEVEL, like first lines in the controller, the following hearders:

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="document.pdf"');
header('Content-Transfer-Encoding: binary');