问题
I am getting this error when I an downloading a pdf file using MPDF. I am loading the code here below:
$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');
UPDATE Attaching screenshot here:
Any help will be greatly appreciated. Thank you
回答1:
Alright I have Simulated the case and what Worked is as follows
Downloaded Library from mPDF Library using Codeigniter
Placed it in application/third_party. Created a File M_pdf.php in application/libraries
<?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);
}
}
?>
Created a Test function in My Controller to test. At first I was trying to save it and getting an error like
But then I replace the F switch in Output with D for download
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");
}
And it worked. Created a PDF file like
回答2:
File Name : libraries/M_pdf.php
Folder Name : third_party/mpdf
include_once APPPATH.'/third_party/mpdf/mpdf.php';
class 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);
}
}
Controller File
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");
}
https://i.stack.imgur.com/eplfX.png
来源:https://stackoverflow.com/questions/42777786/codeigniter-call-to-a-member-function-writehtml-on-a-non-object