它不是生成PDF,而是在浏览器上显示HTML页面

问题描述 投票:1回答:1

我正在使用mpdf生成pdf。它实际上将HTML文件转换为pdf。 HTML文件被一些数据填满。控制器中的代码是:

$pdfFilePath = APPPATH.'invoice/firstinvoice1901.pdf';

        //load mPDF library
        $this->load->library('m_pdf');
        $html = $this->load->view('admin/payments/viewinvoice',$this->data,true);

       //generate the PDF from the given html
        $this->m_pdf->pdf->WriteHTML($html);

        //save it on server.
        $this->m_pdf->pdf->Output($pdfFilePath,"F"); 

现在运行代码后,它不会生成pdf,而是填充html页面并在浏览器上显示此页面。

欢迎任何帮助。

codeigniter pdf mpdf
1个回答
0
投票
  1. 通过使用MPDF库的内置方法

$ mpdf->输出('MyPDF.pdf','D');

要么

  1. 你可以通过强制下载方法来实现。 $filename = "fileName.pdf"; if (file_exists($filename)) { header('Content-type: application/force-download'); header('Content-Disposition: attachment; filename='.$filename); readfile($filename); }
© www.soinside.com 2019 - 2024. All rights reserved.