我已将pdf文件存储到数据库中,即blob类型。 现在我想显示pdf,如
$sqll="select * from pdff";
$query=mysql_query($sqll) or die(mysql_error());
$result=mysql_fetch_array($query);
$content=$result['pdf'];
<object data="<?php echo $content;?>" type="application/pdf" style="height:200px;width:60%"></object>
但在浏览器中显示..
> endobj 6 0 obj << /ProcSet [ /PDF /Text /ImageB /ImageC /ImageI ] /ColorSpace << /Cs1 7 0 R /Cs2 10 0 R >> /ExtGState << /Gs2 34 0 R /Gs1 35 0 R >> /Font << /F1.0 31 0 R >> /XObject << /Im4 21 0 R /Im1 8 0 R /Im3 16 0 R /Im2 11 0 R /Im5 26 0 R /Im6 32 0 R /Fm3 23 0 R /Fm1 13 0 R /Fm2 18 0 R /Fm4 28 0 R >> /Properties << /Pl2 36 0 R /Pl1 37 0 R >> >> endobj 23 0 obj << /Length 24 0 R /Filter /FlateDecode /Type /XObject /Subtype /Form /FormType 1 /BBox [649 536 669 556] /Resources 25 0 R /Group << /S /Transparency /CS 10 0 R /I true /K false >> >> stream xMŽAƒ0ï}žÀĉmȹ/àÄU+Íÿ¥:(\|˜]ïî etc
我试过
<object data="<?php echo base64_decode($content);?>" type="application/pdf" style="height:200px;width:60%"></object>
但没有用...请帮助meeee
答案 0 :(得分:7)
如果您的数据仍在Blob
,则需要使用base64_encode()
对数据进行编码。
请试一试
<object data="data:application/pdf;base64,<?php echo base64_encode(content) ?>" type="application/pdf" style="height:200px;width:60%"></object>
答案 1 :(得分:1)
我知道该线程很旧,但是最近我有一个类似的问题要解决,并撰写了此快速指南进行介绍。 https://medium.com/@alexmoran_19787/display-pdf-from-blob-file-11996146dbc0
基本上取决于将pdf输入数据库时是否加上斜线,可以通过以下方式查看它 我在我的控制器中将此信息传递给了php页面。设置标题,如果添加了斜杠,请确保将其删除,否则最终将得到原始数据或空白屏幕。
$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,
]);
这是来自php页面。
<object data="data:application/pdf;base64,<?php echo base64_encode($content);?>" type="application/pdf" height="100%" width="100%"></object>
答案 2 :(得分:0)
我希望以下内容能够完全满足您的要求:
2019-10-09 23:39:22.936 +02:00 [DBG] ======================================================================
2019-10-09 23:39:22.999 +02:00 [DBG] MyAppDELFOR (0.10.1 2019-10-09)
2019-10-09 23:39:22.999 +02:00 [DBG] ----------------------------------------------------------------------
2019-10-09 23:39:23.015 +02:00 [DBG] stageDirectory: 'c:\EDIAbc\Company_received_stage'
2019-10-09 23:39:23.015 +02:00 [DBG] oftpIncomingDirectory: 'c:\EDIAbc\Company_incoming'
2019-10-09 23:39:23.015 +02:00 [DBG] archiveDirectory: 'c:\EDIAbc\Company_received_archive'
2019-10-09 23:39:23.015 +02:00 [DBG] ----------------------------------------------------------------------
2019-10-09 23:39:23.061 +02:00 [WRN] The stage file 'c:\EDIAbc\Company_received_stage\DELFOR_010091_20191001' already exists and is to be deleted.
2019-10-09 23:39:24.905 +02:00 [INF] Processing 'c:\EDIAbc\Company_received_stage\DELFOR_010086_20191001'
2019-10-09 23:39:30.281 +02:00 [INF] Processing 'c:\EDIAbc\Company_received_stage\DELFOR_010087_20191001'
2019-10-09 23:39:34.109 +02:00 [INF] Processing 'c:\EDIAbc\Company_received_stage\DELFOR_010088_20191001'