【问题标题】:how to include pdf download in codeigniter如何在codeigniter中包含pdf下载
【发布时间】:2017-07-21 08:24:52
【问题描述】:

我想保留一个按钮来下载 pdf 文件。但是库文件会显示在视图中。有人请帮助我。在此先感谢。 控制器代码:

public function pdf()
{
    //load library
    $this->load->library('pdf');
    $pdf = $this->pdf->load();
   // retrieve data from model
    $data['DocFile'] = $this->Docauth->get_items();
    $data['DocFileName'] = "items";
    ini_set('memory_limit', '256M'); 
   // boost the memory limit if it's low ;)
    $html = $this->load->view('Docauth_v', $data, true);
   // render the view into HTML
    $pdf->WriteHTML($html); // write the HTML into the PDF
    $output = 'Docauth' . date('Y_m_d_H_i_s') . '_.pdf';
    $pdf->Output("$output", 'I'); // save to file because we can
    exit();

查看文件

<div class="form-group">                                                            
    <label class="control-label col-md-3">View File</label>
    <div class="col-md-5">
        <input name="DocFile" id="DocFile" class="form-control"` type="text" >
    </div>
    <a href="Docauth/pdf"><span class="glyphicon glyphicon-plus"></span></a> 
</div>

【问题讨论】:

标签: php codeigniter


【解决方案1】:

Output 函数中的I 选项将文件内联发送到浏览器。您需要使用D 选项:

$pdf->Output("$output", 'D'); 

更多信息在这里:http://www.rubydoc.info/gems/rfpdf/1.17.1/TCPDF%3AOutput

@参数字符串:dest

发送文档的目的地。它可以采取其中之一 以下值:

I:将文件内联发送到浏览器(默认)。该插件使用 如果可供使用的话。当一个人选择 生成 PDF 的链接上的“另存为”选项。

D:发送到浏览器并强制下载指定名称的文件 按名称。

F: 以 name 指定的名称保存到本地服务器文件。

S:将文档作为字符串返回。名称被忽略。

FI:相当于F+I选项

FD:相当于F+D选项

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 2017-10-27
    • 2016-06-12
    • 1970-01-01
    • 2017-10-09
    • 1970-01-01
    • 2011-01-21
    相关资源
    最近更新 更多