2

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
  • Your sample bytes do not decode to a complete PDF file, it is cut of at some early point. Commented Nov 15, 2013 at 11:58

3 Answers 3

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

just worked for me.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.