Laravel:以pdf格式将字节数组输出到浏览器

Laravel:以pdf格式将字节数组输出到浏览器,laravel,pdf,stream,Laravel,Pdf,Stream,我收到一个外部api的响应,其中包含一个字节数组,我想转换成pdf 从api 到目前为止,我在laravel中尝试了以下代码,但没有成功 $data从api接收 return response($data) ->withHeaders([ 'Content-Type'=> 'application/pdf' ]); 诀窍是设置头以强制下载 return response($dat

我收到一个外部api的响应,其中包含一个字节数组,我想转换成pdf

从api

到目前为止,我在laravel中尝试了以下代码,但没有成功

$data从api接收

return response($data)
                ->withHeaders([
                    'Content-Type'=> 'application/pdf'
                ]);
诀窍是设置头以强制下载

return response($data, 200, [
    'Content-type'        => 'application/pdf',
    'Content-Disposition' => 'attachment; filename="api.pdf"',
]);

您也可以用内联替换附件,以便在浏览器中呈现pdf。大多数现代浏览器都支持此功能。

如果使用guzzle,您可以尝试使用getContent方法