Javascript 从laravel返回pdf而不是pdf url

Javascript 从laravel返回pdf而不是pdf url,javascript,php,laravel,pdf,Javascript,Php,Laravel,Pdf,我用的是拉威尔。我不想将pdf的url返回到前端,因为它位于谷歌云中,我不想看到链接。这就是为什么我需要直接返回pdf,并让用户通过浏览器下载它 我试过这个: return response()->json(['data' => file_get_contents(Storage::url($cert_path))]); //this says: malformed utf-8 characters, 500 error $file = file_get_contents(Sto

我用的是拉威尔。我不想将pdf的url返回到前端,因为它位于谷歌云中,我不想看到链接。这就是为什么我需要直接返回pdf,并让用户通过浏览器下载它

我试过这个:

return response()->json(['data' => file_get_contents(Storage::url($cert_path))]); 
//this says: malformed utf-8 characters, 500 error
$file = file_get_contents(Storage::url($cert_path));
$file = mb_convert_encoding($file, 'HTML-ENTITIES', "UTF-8");
return response()->json(['data'=>$file]);
//this returns pdf, but in front, when i have a download code of js, when I download it, the whole pdf is empty.
然后我在谷歌上搜索并尝试了以下方法:

return response()->json(['data' => file_get_contents(Storage::url($cert_path))]); 
//this says: malformed utf-8 characters, 500 error
$file = file_get_contents(Storage::url($cert_path));
$file = mb_convert_encoding($file, 'HTML-ENTITIES', "UTF-8");
return response()->json(['data'=>$file]);
//this returns pdf, but in front, when i have a download code of js, when I download it, the whole pdf is empty.
pdf的url是正确的,因为我可以转到该url并查看pdf

如何成功返回pdf

我还将包括javascript下载代码:

 var blob = new Blob([pdf], {
         type: 'application/pdf'
    });
   var link = document.createElement('a');
   link.href = window.URL.createObjectURL(blob);
   link.download = "ffa.pdf";
   link.click();

只需打开一个简单的HTML链接,在控制器中返回具有良好标题的文件,以在navigator中显示PDF。我不明白你的意思。不要返回
json
。Gotchya。因此,我将返回response()->文件,但我还想随该文件返回一些json。可能吗?不,不可能。