【发布时间】:2019-10-18 21:20:21
【问题描述】:
我正在使用 AJAX 返回我的 laravel 控制器转换为 pdf 的 html(因为 js 完成了一些计算)。 然后,将生成的 pdf 保存在我的文件夹中后,我需要在新选项卡中打开它。 我不想使用 storage/public 文件夹。因为存储目录下还有其他私人文件夹,我正在保存。所以我无法获得他们与laravel的链接。
在我的控制器中,我有:
$pdf = PDF::loadHTML($pdf_html)->setPaper('A4')->setOption('header-html', $header)->save($filepath.$filename);
$headers = [
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'inline',
];
return Response::make(file_get_contents($filepath.$filename), 200, $headers);
我的js:
$.ajax({
method: "POST",
url: '/generatepdf',
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
success: function (data) {
console.log(data);
/*What to do here?*/
}
【问题讨论】: