0

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>
  • If this was a static PDF file, and had nothing whatsoever to do with your database - how would you get the page to display it _then_? Would you copy&paste the binary PDF content into the HTML document at a more or less arbitrary position? No, of course you would not. So it should be pretty plain obvious, that just echoing the data into the document like you tried in the code you have shown can’t be the right approach either. – CBroe Dec 11 '17 at 10:16

1 Answers1

0

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.

user1039663
  • 1,230
  • 1
  • 9
  • 15
  • I have used javascript ( Reference http://jsfiddle.net/ugD5L/126/) but the problem with this is even the student name and other details are displayed inside table (row format). Do you know how to resolve this – Rajeshwari Nesargi Dec 11 '17 at 10:37