如何从控制器 PHP (laravel) 在新选项卡中打开 pdf 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41744513/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to open a pdf file in new tab from controller PHP (laravel)
提问by Sulu.MeanStack
Hi I am new to php programming. I am using laravel 5.2 now.
嗨,我是 php 编程的新手。我现在使用 laravel 5.2。
I have used an external service to create a pdf from my html page. For that I have used pdfcrowd. I wrote the content to a pdf file in my local system. Its location is /var/www/html/testproject/test_pdf.pdf
.
我使用外部服务从我的 html 页面创建了 pdf。为此,我使用了 pdfcrowd。我将内容写入本地系统中的 pdf 文件。它的位置是/var/www/html/testproject/test_pdf.pdf
。
It works fine. Now my requirement is that, I have to open that pdf file in a new tab from my controller. My controller name is adminController. Inside that I used a function to open the pdf.
它工作正常。现在我的要求是,我必须在控制器的新选项卡中打开该 pdf 文件。我的控制器名称是 adminController。在里面我使用了一个函数来打开pdf。
Please see the code below:
请看下面的代码:
public function open_pdf() {
$file_location='/var/www/html/testproject/test_pdf.pdf';
----------?
}
Please suggest your ideas.
请提出你的想法。
回答by Sulu.MeanStack
The important thing to understand is that, we can't open a new tab from php controller. So In the view page (testpage.blade.php) I used 'target="_blank" code in a tag. please see the code below:
<a href="{{ url('/') }}/testproject/openpdf"> target="_blank"
要了解的重要一点是,我们无法从 php 控制器打开一个新选项卡。所以在视图页面 (testpage.blade.php) 中,我在标签中使用了 'target="_blank" 代码。请看下面的代码:
<a href="{{ url('/') }}/testproject/openpdf"> target="_blank"
回答by Vishnu S Babu
Try to add target="_blank"
in your html tags it will work fine.
You may have use like this
尝试target="_blank"
在您的 html 标签中添加它会正常工作。你可能有这样的用法
<a href="{{ url('/') }}/testproject/openpdf">
please try with this
请试试这个
<a href="{{ url('/') }}/testproject/openpdf" target="_blank">