I have stored pdf file into database i.e blob type. Now I wanna display pdf like
$sqll=\"select * from pdff\";
$query=mysql_query($sqll) or die(mysql_error()
If your data still in Blob
, you need to encode your data using base64_encode()
.
Please try it
<object data="data:application/pdf;base64,<?php echo base64_encode(content) ?>" type="application/pdf" style="height:200px;width:60%"></object>
I hope the following will do exactly what you want:
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename=name.pdf');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
@readfile("data:application/pdf;base64,$content");
I know this thread is old but I recently had a similar issue to solve and wrote this quick guide to cover it. https://medium.com/@alexmoran_19787/display-pdf-from-blob-file-11996146dbc0
Basically Depending on if you addslashes or not when inputing the pdf into the database you can view it by the following I had this in my controller and passed the info to a php page. Setting the headers and if you addslashes make sure to stripslashes otherwise you will just end up with the raw data or blank screen.
$content = stripslashes($text["file"]);
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename=document.pdf');
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');
$this->load->view("administrator/load_pdf", [
"title"=>"Display PDF",
"pdf"=>$content,
]);
This is from the php page.
<object data="data:application/pdf;base64,<?php echo base64_encode($content);?>" type="application/pdf" height="100%" width="100%"></object>