Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Well. I've a pdf file encoded as base64 string. How to get the actual pdf using PHP by specifying Content-type:application/pdf in header function or any other method.?

URL for base64 encoded string : 

http://jenson.in/base64pdf.txt

Thanks In Advance.

Cheers..:)

share|improve this question

closed as not a real question by Gung Foo, Jocelyn, Fabio, RDC, Shaz Jun 10 at 18:40

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

up vote 1 down vote accepted

Try this piece of code

$pdf_base64 = "base64pdf.txt";
//Get File content from txt file
$pdf_base64_handler = fopen($pdf_base64,'r');
$pdf_content = fread ($pdf_base64_handler,filesize($pdf_base64));
fclose ($pdf_base64_handler);
//Decode pdf content
$pdf_decoded = base64_decode ($pdf_content);
//Write data back to pdf file
$pdf = fopen ('test.pdf','w');
fwrite ($pdf,$pdf_decoded);
//close output file
fclose ($pdf);
echo 'Done';
share|improve this answer
Thanks Samy, This is what I wanted..Cheers..:) But I've got a -Ve vote for my Query! Was there anything wrong in my question? – Jenson M John Jun 10 at 11:35
1  
i don't know who voted you down ? i will give you thump up – SamyMassoud Jun 10 at 11:36
Thanks..Cheers..:) – Jenson M John Jun 10 at 12:22

Not the answer you're looking for? Browse other questions tagged or ask your own question.