Cetak file PDFmenggunakan MPDF pada Codeigniter

Berikut cara membuat PDF File dengan MPDF

Sofware yang dibutuhkan:

1. Download XAMPP
2. Download CodeIgniter
3. Download MPDF (libraries)

---

1. Instalasi XAMPP pada computer anda.
2. Buatlah folder aplikasi pada folder htdocs
3. Paste folder codeigniter di dalamnya.
4. Paste folder MPDF pada folder library
5. Buat file M_pdf.php pada folder library

< ? p h p

//include_once APPPATH.'/third_party/mpdf/mpdf.php';
require_once dirname(__file__).'/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);
 }
}


---
Controller
Buatlah file controller pada folder controllers misalnya cetak.php

< ? p h p

//File in controller Indonesia and save highchart in assets folder
defined('BASEPATH') OR exit('No direct script access allowed');
class Cetak extends CI_Controller {

public function __construct()
 {
 parent::__construct();
  $this->load->library('M_pdf');

  $this->load->helper('url');
 }

public function index()
 {
  $this->load->view('view_cetak');
 }


}

View
Buatlah file view pada folder views misalnya view_cetak.php




< ? p h p

$html = 'coba';
///////////////////////////
  $this->m_pdf->pdf->WriteHTML($html);
  $this->m_pdf->pdf->Output();


////////////////////////

Selamat mencoba



Powered by Blogger.