Code Igniter : Export Data ke File PDF

Studi Kasus : Export Data Mysql Database ke dalam file PDF dalam Code Igniter.
Kebutuhan :
1. Webserver package, already installed.
2. Code Igniter Bundle.
3. Cezpdf library –> download here

Adakalanya, ketika kita membuat aplikasi, kita akan membutuhkan untuk mengexport data ke dalam file pdf (selain dari file excel), misalkan untuk membuat surat atau laporan tertentu. Dengan library cezpdf (karya Wayne Munro ), membuat laporan dalam bentuk pdf tidak akan terlalu sulit.

A. Mempersiapkan Database
1. Buat database dengan nama db_tutorial.
2. Buat tabel dengan nama tb_member, dengan struktur tabel dibawah ini,

3. Insert-kan beberapa sample data dalam tb_member, misal seperti data dibawah ini,

4. Okay, done with database.

B. Mempersiapkan file dan struktur direktori
1. Install Codeigniter, dengan mengekstrak bundle CI dan menempatkannya dalam document root anda.
2. Atur setting database (system-application-config-database.php) dengan setting database yang akan digunakan (db name : db_tutorial)
3. Atur config base url (system-application-config-config.php)
4. Letakkan file cezpdf.php dan class.pdf.php (hasil download Cezpdf library diatas) dalam folder system-application-libraries
5. Letakkan file pdf_helper.pdf dalam folder system-application-helper.
6. Ok πŸ˜€

C. Membuat model
1. Ketikkan script berikut ini,
[sourcecode language=”php”]
class Member_model extends Model {
function Member_Model() {
function alldata()
$getData = $this->db->get();
if($getData->num_rows() > 0)
return $getData->result_array();
else return null;
2. Simpan dengan nama member_model.php dalam folder system-application-models

D. Membuat Controller
1. Ketikkan script berikut ini,
[sourcecode language=”php”]
class Member_con extends Controller {
public function __construct() {
public function index() {
$data[‘member’] = $this->member_model->alldata();
$this->load->view(‘member_view’, $data);

function topdf () {
$data[‘member’]= $this->member_model->alldata();
$titlecolumn = array(
‘no’ => ‘no’,
‘name’ => ‘name’,
‘address’ => ‘address’
$this->cezpdf->ezTable($data[‘member’], $titlecolumn,’Member Data’);
2. Simpan dengan nama member_model.php dalam folder system-application-models

E. Membuat View
1. Ketikkan script berikut ini,
[sourcecode language=”php”]
<h4>Member Data</h4>
<?php if(count($member) > 0) { ?>
<table border="1">
foreach($member as $rows) {
echo "<tr>";
echo "
<td>". $rows[‘no’]."</td>
<td>". $rows[‘name’] ."</td>
<td>". $rows[‘address’] ."</td>
"; } ?>
<?php } ?>
<br> <br>
<a href='<?php echo base_url(); ?>index.php/member_con/topdf’><span

style=’color:green;’>Export to Pdf</span></a>
[/sourcecode]2. Simpan dengan nama member_model.php dalam folder system-application-models

F. Testing code
1. Buka http://localhost/ci_tutor/index.php/member_con. Anda akan melihat data yang ada dalam tb_member seperti gambar dibawah ini,

2. Klik link export to pdf untuk mengeksport data ke dalam file pdf.
3. Maka secara otomatis browser anda (atau download manager) akan men-download file pdf.
4. Buka file pdf, anda akan melihat data dari tb_member tertampil dalam file pdf tersebut πŸ™‚ Lihat gambar dibawah.

Happy coding πŸ˜€

Oleh littleflow3r

obviously, a girl. with sweet smile, off course. turning her 21 years trapped on Informatics departement and just started to having some crush with it lately. she uses wordpress. she loves php. she loves to satisfied her shopping hobbies just via looking around in online shop. oh yeah, she got an A for her english subject^^

22 replies on “Code Igniter : Export Data ke File PDF”

Mabosway substitute sites and mobile sports login friends – There
are lots of online gambling agent sites scattered upon the internet.
Each of these sites has offers and features provided, including the
types of gambling games available. Many online gambling sites deserted meet the expense of 1 to 3 types of games and certainly have excellent games they offer.

Mabosway.com is an online gambling agent site that offers not lonely
1 or 3 types of gambling games but 7 fascinating types of gambling games that you can play.

This proves that Mabosway is the most total betting site that offers not
solitary online soccer gambling, but Casino, Poker, Toto 4D, Bola Tangkas,
Fish Hunter and online cockfighting gambling. This site is known as Mabosway Indonesia for members who come from Indonesia.

Various types of online gambling games are adequately supported by the maximum encourage from Mabosway.com.
One of them is the Customer sustain feature which is 24 hours standby
to advance accumulation and dissolution transactions for members.
How to register is afterward simple to do, especially for beginner bettors
who are starting to bet for the first time.

How to Apply for Mabosway

How to register mabosway is totally easy for everyday people who desire
to begin playing online gambling. You by yourself have to click the
belong to NOW button upon the home page which will go directly to the registration form page.
After successfully registering you will get a user ID as an identity
in the game. After everything is done, you are officially allied and become a member.

After you officially become a advocate you are offered to
choose the type of online gambling game that you can play.
Here are 5 types of favorite online gambling games that you can produce a result at Mabosway.com.

Panduanjudi Login

Panduanjudi is a trusted and attributed poker site from PKV games server.
We present 9 types of complex games that can be played using just one ID.
The games we pay for attach poker, domino99, bandarq, aduq, sakong,
bandar66 and also capsa susun. In accessory to having a large variety
of games, http://www.Panduanjudi.com moreover has several handsome promos that
can be enjoyed directly after instinctive registered as a member.

like resolved weekly cashback promos that are calculated from
the total turnover, both winning and losing. moreover Panduanjudi essentially
appreciate if there are members who invite friends
or family to pretend on our site by giving a referral other
of 10% to 20% of the number of turnover downline invited to play.

To be the best poker site, Panduanjudi is always a pain to augment our services
to be practiced to have the funds for the best experience in playing poker at our
place. One of the ways is the Gambling lead provides
a means of payment that reaches every elements of Indonesian society.
By committed next leading banks and helpful Simpati and XL financial credit
deposits. As without difficulty as which players can create deposits using
E-wallets such as GoPay, OVO and Funds. supplementary than those mentioned above, of course there are nevertheless advantages in Panduanjudi to vacillate to
become the best poker sites such as:

There are therefore many popular online slot games
that you can locate upon the internet. all of them give on the order
of the similar upheaval and of course the abundant abet that you can rudely acquire overnight.
Getting wealthy in a short epoch is now no longer just a
goal because it is doable to do.

One of the online gambling that you should attempt to enjoy is called online slots.

This game has been just about for hundreds of years and is
still well-liked today. You could say slot gambling games are a type of gambling that has evolved as a result
rapidly, starting from the shape, appearance, to the game format.
No gambling game can be as advocate as the newest online slots.

For those of you who are just starting to scrutinize the online
gambling business, here we will allocation basic tips and behavior for execution in online slot gambling
games. These tips will not encourage you keep winning in every game but will make
your chances of winning better and edit the number of losses you will encounter.

link to the resolution Mabosway sports betting interchange by registering – Are you looking for an looking for excitement and new experience in the
world of online gambling? You have come to the right place,
because here you can associate us, the best and most trusted gambling site agent in Indonesia!

We are privileged to be nimble to meet the expense of the best servants to members who are always loyal to
trust us and make us a gambling partner. Therefore, we have prepared various types of fun and
popular games such as Mabosway sports betting, casino, lottery,
and others.

Not single-handedly that, there are next many promos that we will have enough money and
of course it is every aimed at the benefit of the members.
all the facilities that are normal for you following you become a member here.
Here are some of our advantages exceeding new sites:

The mass and invalidation process is fast and accurate
Members’ personal data and identities are always safe and will not leak to supplementary parties
Mabosway login, one addict ID that can be used for various types of games
Customer staff who are always ready to help you 24/7
Unlimited Bonuses and Promos
The best support supported by years of experience has made Mabosway
always trusted by its members and earned the title as the best gambling site agent in Indonesia.

Not many online gambling sites in Indonesia have ascribed situation status and have licenses issued by relevant authorities.
In addition, the level of consumer service for online gambling sites can yet be
no question low because of the 100 affable online gambling sites, deserted
about 10-15 sites are dexterous to allow professional support and
meet standards.

Therefore, you cannot arbitrarily pick an online gambling site to be a playing partner.
There are many criteria and factors that must be considered to create an online gambling site a area to shelter and
save game deposits. However, it will acknowledge time and effort to locate a trusted site
as soon as this.

Hence, in this article we would considering to come up with the
money for important recommendations roughly trusted and certified online gambling sites in Indonesia.
By becoming a fanatic of this gambling site, it is sure that you will be release from doubt and one step closer to success.

Online gambling is no longer just a game but a issue that can take on you to a brighter future.

Like any extra situation in the world, every step you acknowledge will have alternative
risks and benefits. No human instinctive can always make a profit in every business, and no one can always avoid losing.
all that can be ended is to minimize losses and bump profits until finally the profits create
losses not felt.

ko muncul error seperti ini yah. .
Fatal error: Cannot use object of type stdClass as array in C:\xampp\htdocs\foxpro\system\libraries\cezpdf.php on line 695

setelah di perbaiki dia berhasil proses namun saat di pdf dia memberikan peringatan seperti ini….
” Format error:not a pdf a corrupted.” PERINGATAN
mohon pencerahan……..

maaf masih newbiew euy…..
proses berjalan lancar….Tp ko hasil pdf nya tidak menampilkan data…..
Mohon pencerahan…. πŸ˜›
terima kasih ini sngat membantu….
mudah2n Tuhan membalas,,,,,

kok muncul error seperti ini ?
“Cannot use object of type stdClass as array in C:\wamp\www\Intranet\application\libraries\cezpdf.php on line 695”

saat saya coba buka url ini


kug gini ya? salahnya apa ya?

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\htdocs\www\CodeIgniter\system\codeigniter\Common.php on line 130

Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\htdocs\www\CodeIgniter\system\codeigniter\Common.php on line 136
A PHP Error was encountered

Severity: 8192

Message: Function set_magic_quotes_runtime() is deprecated

Filename: codeigniter/CodeIgniter.php

Line Number: 60

The URI you submitted has disallowed characters.

Makasih gan tutorilanya.. sangat bermanfaat

Untuk Mahfud yg masih ada error.
Coba copy-kan folder fonts ke root direktori CodeIgniter (folder fonts berada satu dg folder system),
dan pdf_helper.php ke system/aplication/helper


A PHP Error was encountered

Severity: Warning

Message: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Krasnoyarsk’ for ‘7.0/no DST’ instead

Filename: libraries/class.pdf.php

Line Number: 689

A PHP Error was encountered

Severity: Warning

Message: date() [function.date]: It is not safe to rely on the system’s timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘Asia/Krasnoyarsk’ for ‘7.0/no DST’ instead

Filename: helpers/pdf_helper.php

Line Number: 24

A PHP Error was encountered

Severity: Notice

Message: Undefined index:

Filename: libraries/class.pdf.php

Line Number: 1631

denis => coba ini.

Ganti nama file class.ezpdf.php menjadi cezpdf.php agar lebih mudah.
Lalu modifikasi pad file cezpdf.php pada statement include di baris 3 menjadi seperti ini :


jangan lupa copy kan dulu file cezpdf.php dan class.pdf.php ke folder system/aplication/libraries dan pdf_helper.php ke system/aplication/helper…
selamat mencoba…

saya punya error seperti ini mas :

Fatal error: Class ‘Cpdf’ not found in C:\xampp\htdocs\lms\system\libraries\cezpdf.php on line 5

knp ya?


keren tutorialnya mas…..tapi kalo mau menampilkan datanya per baris gmn mas?nanti dari field tsb bisa dipakai secara terpisah satu persatu..bisa ga kayak gt mas…mohon pencerahannya ya
terima kasih…

Tinggalkan Balasan ke ardian Batalkan balasan

Alamat email Anda tidak akan dipublikasikan. Ruas yang wajib ditandai *

This site uses Akismet to reduce spam. Learn how your comment data is processed.