简体   繁体   English

如何将BLOB数据(存储在数据库中)转换为pdf

[英]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. 我将blob数据存储在数据库中,该数据库包含整个班级的门票。 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) 我已经过滤并显示了每个学生的大厅票,现在,我面临的问题是当我尝试将显示的大厅票转换为pdf格式时,我无法做到(无论我过去使用哪种方法都无法显示)努力在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. 将Blob转换为base64,并将其与数据网址一起显示到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. 使用适当的MIME类型非常重要,请参阅PDF文件的正确MIME媒体类型 ,以使pdf显示而不是下载,如果需要,反之亦然。

  • split your code into two phps: one for the page and other for the data. 将您的代码分为两个php:一个用于页面,另一个用于数据。 In the one with the page place an iframe and point with the url to the second php. 在带有页面的页面中放置一个iframe,然后将其网址指向第二个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. 在这种情况下,也必须对PDF文件使用正确的MIME媒体类型,这很重要,它没有使用base64,但是您必须确保使用适当的字符集或函数,以确保数据php将正确的字节写入流中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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