Menampilkan PDF Di Codeigniter

 Menampilkan PDF Di Codeigniter

1.Buatlah Controller Welcome.php

<?php

defined('BASEPATH') OR exit('No direct script access allowed');


class Welcome extends CI_Controller {


public function index()

{

$this->load->library('dompdf_gen');

$data['ambil_pesanan'] = $this->db->query("select * from tb_pengguna")->result();

$this->load->view('test_pdf',$data);

$paper_size = 'A4' ;

$orientation = 'landscape';

$html = $this->output->get_output();

$this->dompdf->set_paper($paper_size,$orientation);


$this->dompdf->load_html($html);

$this->dompdf->render();

$this->dompdf->stream('laporan_Pemesanan.pdf', array('Attachment' => 0 ));

}

}



2.Buatlah View  test_pdf.php

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<h1><center>HALAMAN 1</center></h1>
<table width="101%" border="1" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td>Nama </td>
    <td>Jenis Kelamin</td>
    <td>Telephone</td>
    <td>Status</td>
    <td>No ID</td>
    <td>Aksi</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>

</body>
</html>


3.Buatlah Library pada application/libraries/ dengan nama Dompdf_gen.php



<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* Name:  DOMPDF
* Author: Jd Fiscus
*   jdfiscus@gmail.com
*         @iamfiscus
*          
*
* Origin API Class: http://code.google.com/p/dompdf/
* Location: http://github.com/iamfiscus/Codeigniter-DOMPDF/
*          
* Created:  06.22.2010 
* Description:  This is a Codeigniter library which allows you to convert HTML to PDF with the DOMPDF library
*/

class Dompdf_gen {
public function __construct() {
require_once APPPATH.'third_party/dompdf/dompdf_config.inc.php';
$pdf = new DOMPDF();
$CI =& get_instance();
$CI->dompdf = $pdf;
}
}


4.Buatlah file pada application/third_party/ dg nama dompdf
atau download file disini





Download File Click here

Menampilkan PDF Di Codeigniter Menampilkan PDF Di Codeigniter Reviewed by Leo on 04:08 Rating: 5

No comments