How to create a pdf file from a binary file?

How to create pdf file from binary file received from database in php5? It comes in base64 encoding, and I just decoded it, but I donโ€™t know what to do next ...

+8
php pdf-generation binaryfiles
source share
2 answers

Binary data is simply the actual file, or rather, the important contents of this file, without the file name.

$base64 = /* some base64 encoded data fetched from somewhere */; $binary = base64_decode($base64); 

And there you have the file data / file contents in the $binary variable. From here, it depends on what you want to do. You can write the data to a file and you will get an โ€œactualโ€ PDF file:

 file_put_contents('my.pdf', $binary); 

You can output the data to the browser with the appropriate header, and the user will receive something that looks like a PDF file:

 header('Content-type: application/pdf'); header('Content-Disposition: attachment; filename="my.pdf"'); echo $binary; 
+25
source share

I repeat the last sentence. :) I do not know what the question is! :). If you want to use the file in a browser, you can set the headers and streaming decoded content. Or, if you want the file to be as it is, write to the file system and use it. Please clarify your question!

Thanks!!

-one
source share

All Articles