kali ini saya akan membahas mengenai dompdf untuk export data di codeigniter.
1. unduh https://github.com/dompdf/dompdf/ ** saya memakai versi 0.6.2
copy folder ke libraries/ rename dengan nama folder dompdf
2. buat file di folder libraries/ nama file pdf.php
[code]
<?php defined('BASEPATH') OR exit('No direct script access allowed');
require_once(dirname(__FILE__) . '/dompdf/dompdf_config.inc.php');
class Pdf //extends DOMPDF
{
protected function ci()
{
return get_instance();
}
public function __construct() {
$pdf = new DOMPDF();
$CI =& get_instance();
$CI->dompdf = $pdf;
}
}
?>
[/code]
3. buat method di controller yang akan memanggil fungsi print pdf. contoh :
[code]
$this->load->library('pdf');
$this->dompdf->load_html('hello world');
$this->dompdf->set_paper("A4", "portrait"); //“portrait” / “landscape”
$this->dompdf->render();
$filename = "mypdf.pdf";
$this->dompdf->stream($filename); // to Download PDF
[/code]
* ganti dgn tcpdf karna ada bug saat tampilkan rowspan & colspan tabel jadi tidak rata
---------------------------------------------------------------------------------------
TCPDF
Langkah 1
unduh TCPDF Klik Disini
Langkah 2
Unzip kemudian pindahkan folder ke application/libraries/tcpdf.
Langkah 3
Buat File baru application/libraries/Pdf.php
[code]
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
require_once dirname(__FILE__) . '/tcpdf/tcpdf.php';
class Pdf extends TCPDF
{
function __construct()
{
parent::__construct();
}
}
/*Author:Tutsway.com */
/* End of file Pdf.php */
/* Location: ./application/libraries/Pdf.php */
[/code]
0 comments:
Post a Comment