当我使用MPDF下载pdf文件时,我收到此错误。我在下面加载代码:
$html = $this->load->view('customer/case_report',$this->data, true);
$pdfFilePath = "output_pdf_name.pdf";
$this->load->library('M_pdf');
$this->M_pdf->pdf->WriteHTML($html);
$this->M_pdf->pdf->Output('CaseReport_CaseNo_'.$caseNo.'.pdf', 'D');
任何帮助将不胜感激。谢谢
答案 0 :(得分:1)
好吧我已经模拟了案例,工作内容如下
从mPDF Library using Codeigniter下载图书馆
将其放在application / third_party中。在application / libraries中创建了一个文件M_pdf.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
include_once APPPATH.'/third_party/mpdf/mpdf.php';
class M_pdf {
public $param;
public $pdf;
public function __construct($param = "'c', 'A4-L'")
{
$this->param =$param;
$this->pdf = new mPDF($this->param);
}
}
?>
在My Controller中创建一个Test功能进行测试。起初我试图保存它并得到像
这样的错误然后我将输出中的F开关替换为D进行下载
public function mdfTest()
{
$pdfFilePath = time()."_order.pdf";
$this->load->library('M_pdf');
$html="<html><h1>This is test pdf</h1></html>";
$this->m_pdf->pdf->WriteHTML($html);
//download it.
$this->m_pdf->pdf->Output($pdfFilePath, "D");
}
它有效。创建了一个像
这样的PDF文件答案 1 :(得分:0)
文件名:libraries / M_pdf.php
文件夹名称:third_party / mpdf
include_once APPPATH。&#39; /third_party/mpdf/mpdf.php' ;;
类M_pdf {
public $param;
public $pdf;
public function __construct($param = '"en-GB-x","A4","","",10,10,10,10,6,3')
{
$this->param =$param;
$this->pdf = new mPDF($this->param);
}
}
控制器文件
public function pdf_create()
{
$this->load->library('M_pdf');
$pdffile = time()."_order.pdf";
$this->m_pdf->pdf->WriteHTML("My First Codeigniter in First Pdf
Create.");
$this->m_pdf->pdf->Output($pdffile, "I");
}