Create a new file in your application/libraries/ name it M_pdf.php and copy past the blow PHP Script.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
<?phpif (!defined('BASEPATH')) exit('No direct script access allowed'); include_once APPPATH.'/third_party/mpdf/mpdf.php'; classM_pdf{ public $param; public $pdf;
publicfunction__construct($param = '"UTF-8","A4","","",10,10,10,10,6,3') { $this->param =$param; //$this->pdf = new mPDF($this->param); $this->pdf = new mPDF('+aCJK','A4','','',32,25,27,25,16,13); $this->pdf->autoLangToFont = true; } }
That is it. You had successfully integrated mPDF in CodeIgniter. Now let’s use it.
2.Edit config.php
edit the application/third_party/mpdf/config.php line44:
1
$this->useAdobeCJK = true;
line67:
1
$this->autoLangToFont = true;
3.How to Use
Load the mPDF library just like your load other CI’s other libraries and then call pdf property. See the blow example code for better understanding.
functionindex(){ $data = []; //load the view and saved it into $html variable $html=$this->load->view('success', $data, true); //this the the PDF filename that user will get to download $pdfFilePath = "1.pdf"; //load mPDF library $this->load->library('m_pdf'); //generate the PDF from the given html //$this->m_pdf->pdf->WriteHTML($html); $content='<table border="1" cellpadding="2" cellspacing="1"><tr><td style="border:1mm solid green">this is 什么</td></tr></table>'; $this->m_pdf->pdf->useAdobeCJK = true; $this->m_pdf->pdf->autoScriptToLang=true; $this->m_pdf->pdf->WriteHTML($content); //download it. $this->m_pdf->pdf->Output($pdfFilePath, "D"); } }