Byte array to pdf file in php

时间秒杀一切 提交于 2020-01-25 05:57:50

问题


I have a byte array in pdf format getting from web service.Now I want to view in PDF file but no luck.

sample byte[]:

JVBERi0xLjQKJeLjz9MKMSAwIG9iaiAKPDwKL01hdHJpeCBbMSAwIDAgMSAwIDBdCi9TdWJ0eXBlIC9Gb3JtCi9GaWx0ZXIgL0ZsYXRlRGVjb2RlCi9MZW5ndGggMTUwMzc3Ci9SZXNvdXJjZXMgCjw8Ci9FeHRHU3RhdGUgCjw8Ci9HUzAgMiAwIFIKL0dTMSAzIDAgUgo+PgovQ29sb3JTcGFjZSAKPDwKL0NTMCA0IDAgUgo+PgovUHJvcGVydGllcyAKPDwKL01DMyAKPDwKL01ldGFkYXRhIDUgMCBSCj4+Ci9NQzIgCjw8Ci9NZXRhZGF0YSA2IDAgUgo+PgovTUMxIAo8PAovTWV0YWRhdGEgNyAwIFIKPj4KL01DMCAKPDwKL01ldGFkYXRhIDggMCBSCj4+Cj4+Ci9YT2JqZWN0IAo8PAovRm0xIDkgMCBSCi9GbTAgMTAgMCBSCi9GbTIgMTEgMCBSCj4+Ci9Gb250IAo8PAovVDFfMyAxMiAwIFIKL1QxXzIgMTMgMCBSCi9UMV8xIDE0IDAgUgovVDFfMCAxNSAwIFIKPj4KL1Byb2NTZXQgWy9QREYgL1RleHRdCj4+Ci9Gb3JtVHlwZSAxCi9UeXBlIC9YT2JqZWN0Ci9CQm94IFswIDAgNjEyIDc5Ml0KPj4Kc3RyZWFtCnic3L1bjy09ciX2/v2K/WgZ2KXknQQEAR5JbdiGgBmogXkYG4askWZst2TrMrDf5q+bwSCZychgXqoqso6MBvo7depUcW/uJNeK21r/+Nsf//d/tbz+0z//9se/+/vl9ef/12//7rc//qv/+6//4fUnf/LHf/ln/8Ofv5bXn/7pv/nzP3v99m9+/9vygv+p1/8JP6XKT/1e/a/wN7//u99S+WZ6Was+lA2vYPTHovMffv/3v/2H/+Z/Xkz4o7eO8Aff/gB/o9sf4L8u/9fBH2z+g4E/mPYH/Udv5eEPKv8hwB+W/AdT/2b4aZ1/nVq2P63zkirBH1z9aW3pDxn6F7q9TFV==


回答1:


I have resolved this issue. Actually it was base64 encodes. I was able to generate the pdf after decoding it using base64_decode.




回答2:


header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="service.pdf"');
echo base64_decode($byte_string);

just worked for me.




回答3:


You could just echo it with headers.

header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="service.pdf"');
echo $byte_string;

header

But I cannot read provided string as PDF.



来源:https://stackoverflow.com/questions/19995415/byte-array-to-pdf-file-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!