简体   繁体   中英

How to convert BLOB data (stored in database) to pdf

I have blob data stored in the database which consists hall tickets of the entire class. I have already filtered and displayed hall ticket for each student, Now, the issue what I am facing is when I am trying to convert the displayed hall ticket in pdf format I am unable to do it( whatever approach I have used to display is not working to display the same in PDF)

<div class="widget-body clearfix" id="print" style="display:none;">
<?php 
     $studId= $this->dashboard_model->getstudId(); 
     $html = implode(" ",$blob);
     echo $html;
?>
</div>


<script>
    $(window).load(function() {
        var studId= <?php echo $studId; ?>;
        $('#print').html('<table style="width:100%;border:thick double #333333;" align="center">'+$('#'+studId).html()+'</table>').css('display', 'block');
        $('#print tr').css('font-size', '10px');
    });

</script>

Here are two possible approaches:

  • convert the blob to base64 and display it with a data url into an iframe. Check docs about Data URLs . It's very important to use appropiate MIME types, see Proper MIME media type for PDF files , in order to make the pdfs are displayed instead of downloaded, or viceversa if wanted.

  • split your code into two phps: one for the page and other for the data. In the one with the page place an iframe and point with the url to the second php. In this case it's important also use Proper MIME media type for PDF files , base64 it's no used but you must be sure to use the appropiate charset or functions to be sure that the data php writes the correct bytes to the stream.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM