[英]How to convert array of byte into pdf?
I am using a web service which returns me array of bytes and i am trying to convert it into pdf but finding some difficulties.我正在使用 web 服务,它返回我的字节数组,我试图将其转换为 pdf 但发现一些困难。
Returned bytes are more than thousand lines so i can not paste all but this is how it starts返回的字节超过一千行,所以我不能全部粘贴,但这就是它的开始方式
%PDF-1.2
%âãÏÓ
1 0 obj
<<
/Type /Catalog
/Pages 2 0 R
/PageMode /UseNone
/ViewerPreferences <<
/FitWindow true
/PageLayout /SinglePage
/NonFullScreenPageMode /UseNone
>>
>>
endobj
5 0 obj
<<
/Length 1683
/Filter [ /FlateDecode ]
>>
stream
xX[SâH~ϯèª}Á©Bú´oH2Ê®8ÎTYµ!jV...
I tried few solutions like我尝试了一些解决方案,例如
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="service.pdf"');
echo hex2bin($byte_string);
or或者
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="service.pdf"');
echo base64_decode($byte_string);
Put your response in varriable, like in $data and if you are working in core php just write将您的响应放入变量中,例如在 $data 中,如果您在核心 php 中工作,只需编写
file_put_contents('your_pdf_name.pdf',$data);
and if you are doing in laravel如果你在做 laravel
file_put_contents(public_path('your_folder_name/your_pdf_name.pdf'),$data);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.