Skip to main content

cara membuat laporan pdf di Codeigniter 2.0

May 24, 2011 by blackdutz3

blackdutz3's picture

Tolong para master CI , saya dapet tugas dri skolah ... suruh bikin report dri website . web saya dari CI 2.0 ...
mohon bantuan nya ....

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

image tidak muncul

June 28, 2011 by aldin, 6 weeks 13 hours ago
Comment: 8447

aldin's picture

saya sudah coba script diatas, sudah jalan.
cuman masalahnya, di file PDF yang dihasilkan IMAGE ga muncul. Gimana ya solusinya ?

Re: cara membuat laporan pdf di Codeigniter 2.0

May 24, 2011 by firgilius, 11 weeks 3 hours ago
Comment: 8221

firgilius's picture

Pake aja dompdf lebih gampang, kita tinggal bkin template halamannya dalam view n panggil dompdf di controller. Caranya donlot dl dompdf di sini http://code.google.com/p/dompdf/downloads/list ane sarananin yg versi 0.6.0 beta, klo dah donlot taro di library (versi ane di library) trs extract n bkin class CI_Pdf buat manggil di controller, noh kasih class-nya:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
 
class CI_Pdf {
 
    function pdf_create($html, $filename, $stream=TRUE)
{
    require_once("dompdf/dompdf_config.inc.php");
    spl_autoload_register('DOMPDF_autoload');
 
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    if ($stream) {
        $dompdf->stream($filename.".pdf");
    } else {
        $CI =& get_instance();
        $CI->load->helper('file');
        write_file($filename, $dompdf->output());
    }
}
}

Nah buat pemanggilan class di controller, contoh:

function export()
    {           
                $this->load->library('pdf');
                $html = $this->load->view('(template htmlnya)', $data, true);
                $this->pdf->pdf_create($html, '(Nama file pdf)');
    }

That's it :)

Premium Drupal Themes by Adaptivethemes