简体   繁体   English

使用 laravel-dompdf 进行 laravel 打印预览

[英]laravel print preview using laravel-dompdf

I am using Laravel 5.4 and using我正在使用 Laravel 5.4 并使用

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

https://github.com/barryvdh/laravel-dompdf 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.因为它会正确下载 pdf,但我希望在视图中预览要打印的内容。 i have googled lot still not able to get it我用谷歌搜索了很多仍然无法得到它

You can use stream() function as stated in documentation here .您可以使用此处文档中所述的stream()函数。

According to documentation of dompdf , When you use stream like this:根据dompdf文档,当您使用这样的流时:

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

In default, you will see a download dialouge box .默认情况下,您将看到一个download dialouge box

But, you can add parameter Attachment value to false so that you can view pdf in browser.但是,您可以将参数Attachment值添加到false以便您可以在浏览器中查看pdf

Here is what you need to do:以下是您需要做的:

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

This might help you.这可能对你有帮助。

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:除了上面的命令,您还需要添加一个 TOP LEVEL,如控制器中的第一行,以下听者:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM