r&OS and codeigniter eksport to pdf report

database yg digunakan:

download r&os library di http://www.ros.co.nz/pdf/

setelah itu kita dapat ganti class.ezpdf.php menjadi ezpdf.php lalu buka source code tersebut dan tambahkan skrip berikut

include_once(APPPATH . 'libraries/class.pdf.php');

kemudian letakkan di dalama folder applikasi/library. copy source code ini

<?php

function prep_pdf($orientation = 'landscape')
{
	$CI = & get_instance();
	
	$CI->cezpdf->selectFont(base_url() . '/fonts');	
	
	$all = $CI->cezpdf->openObject();
	$CI->cezpdf->saveState();
	$CI->cezpdf->setStrokeColor(0,0,0,1);
	if($orientation == 'portrait') {
		$CI->cezpdf->ezSetMargins(50,70,50,50);
		$CI->cezpdf->ezStartPageNumbers(500,28,8,'','{PAGENUM}',1);
		$CI->cezpdf->line(20,40,578,40);
		$CI->cezpdf->addText(50,32,8,'Printed on ' . date('m/d/Y h:i:s a'));
		$CI->cezpdf->addText(50,22,8,'CI PDF Tutorial - http://www.yaniarprayogo.wordpress.com');
	}
	else {
		$CI->cezpdf->ezStartPageNumbers(750,28,8,'','{PAGENUM}',1);
		$CI->cezpdf->line(20,40,800,40);
		$CI->cezpdf->addText(50,32,8,'Printed on ' . date('m/d/Y h:i:s a'));
		$CI->cezpdf->addText(50,22,8,'CI PDF Tutorial - http://www.yaniarprayogo.wordpress.com');
	}
	$CI->cezpdf->restoreState();
	$CI->cezpdf->closeObject();
	$CI->cezpdf->addObject($all,'all');
}

?>

ke helper/pdf_helper.php

Controller

class export extends Controller{
    //put your code here
    public function __construct() {
        parent::Controller();
        $this->load->model('SupplierM');
    }
    /*
     * for suplier convert to pdf
     */
    public function exportsuplier(){
        $data['detail'] = $this->SupplierM->getSupplier();//call the model and save the result in $detail
	$this->load->view('laporan/viewsupplierpdf', $data);
    }
    public function topdfsuplier(){
        $this->load->library('cezpdf');
	$this->load->helper('pdf');
        prep_pdf();
	$data['detail'] = $this->SupplierM->getSupplier();
		$titlecolumn = array(
                    'nosup'=>'nosup',
                    'idsup'=>'idsup',
                    'namasup'=>'namasup',
                    'alamatsup'=>'alamatsup',
                    'kotasup'=>'kotasup',
                    'telpsub'=>'telpsub',
                    'emailsub'=>'emailsub',
                    'tanggal'=>'tanggal'
		);
        $this->cezpdf->ezTable($data['detail'],$titlecolumn,'Supplier data');
        $this->cezpdf->ezStream();
    }

]

Model

class SupplierM extends Model{
	
	//call variable database
	private $tblsupplier = 'suplier';
	
	public function SupplierM(){
		parent::Model();
		$this->CI =& get_instance();
	}
	public function getSupplier(){
		$this->db->select('*');
		$this->db->from('suplier');
		$this->db->order_by('nosup','DESC');
		$getData = $this->db->get();
		if($getData->num_rows() > 0)
		return $getData->result_array();
		else
		return null;
	}
}

viewsupplierpdf.php

<html>
<head><title></title>

</head>
<body>
	<h4>Supplie Data </h4>
	<?php if(count($detail) > 0) { ?>
	<table bordercolor="#FF0000" border="1">
	<tr>
	<th>No Sup</th>
	<th>ID Sup</th>
	<th>Nama Sup</th>
	<th>Alamat Sup</th>
	<th>Kota Sup</th>
	<th>Telp Sup</th>
	<th>Email Sup</th>
	<th>Tanggal Sup</th>
	</tr>
	<?php
	foreach($detail as $rows) {
	echo "<tr>";
	echo "
	<td>".  $rows['nosup']."</td>
	<td>". $rows['idsup'] ."</td>
	<td>". $rows['namasup'] ."</td>
	<td>". $rows['alamatsup'] ."</td>
	<td>". $rows['kotasup'] ."</td>
	<td>". $rows['telpsub'] ."</td>
	<td>". $rows['emailsub'] ."</td>
	<td>". $rows['tanggal'] ."</td>
	"; } ?>
	</table>
	<?php } ?>
	<br> <br>
	<a href='topdfsuplier'><span style='color:green;'>Export All Data</span></a>
        <a href="<?php echo site_url('Laporan/'); ?>"><span style='color:green;'>Back</span></a>
</body>
</html>

2 thoughts on “r&OS and codeigniter eksport to pdf report

    • sorry i will not send your answer to your email, for your trouble you can take font folder after you download r&OS into your root CI, this example :

      copy folder font to your root path application…,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s