Thursday 4 September 2014

Create simple PDF file using CodeIgniter

Assalamualaikum..

Sila rujuk coding seperti di bawah:-

controller - PDF.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php 

class PDF extends CI_Controller
{
 public function __construct() { 
  parent::__construct();
 }
                                   
 function index() 
 {                
  $this->load->library('mpdf');
  $data['topic'] = 'Fail PDF';
  $data['alist'] = $this->db->get('tablename')->result_array(); 
  $html = $this->load->view($this->controller.'/failPDF',$data,true);

  $this->mpdf->AddPage('P');
  $this->mpdf->WriteHTML($html);
  $this->mpdf->Output('Fail PDF', 'D'); 

 }
}
?>


view - PDF/failPDF.php

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
<?php

foreach ($alist as $key => $val) {
 $para .= 'Contoh : '.$val['no_kompaun'].' data <br>';
}

echo 'Isi kandungan fail hendaklah dalam format HTML dan boleh gabung dengan data dari controller. Sekiranya '.$topic
.' melibatkan data berbentuk array hendaklah dibuat diluar dari HTML seperti contoh pada para.<br>'.$para;

?>


----------------------------------------------------------
Disediakan Oleh : Haslina Shamsudin
Sumber : Sistem PHEIS

0 comments:

Post a Comment