cara membuat report pdf dengan php
membuat report pdf dengan php – Banyak sekali orang yang membutuhkan report untuk melaporkan pekerjaan nya ,dengan sangat cepat dan tidak manual
maka dari itu tutorial kali ini adalah report pdf php
yang pengolahan data nya menggunakan program dan data yang di hasilkan adalah report pdf php mysql
Step pertama
cara membuat report pdf dengan php sangat mudah sekali buatlah table seperti script di bawah
1
2
3
4
5
6
7
8
9
10
11
12
|
CREATE TABLE `tb_barang` (
`kode_brg` int(5) NOT NULL AUTO_INCREMENT,
`barcode` varchar(20) NOT NULL,
`nama_brg` varchar(150) NOT NULL,
`harga_brg` int(10) NOT NULL,
`keterangan` tinytext NOT NULL,
`jenis` varchar(30) DEFAULT NULL,
`satuan` varchar(30) DEFAULT NULL,
`stok_brg` int(5) DEFAULT NULL,
`gbr_brg` varchar(40) DEFAULT NULL,
PRIMARY KEY (`kode_brg`)
) ENGINE=MyISAM AUTO_INCREMENT=8 DEFAULT CHARSET=latin1
|
Step kedua
ada beberapa tutorial lainya seperti membuat laporan report pdf dengan php dan html2pdf tapi kita tidak menggunakan html2pdf kita menggunaka Dompdf
report pdf di php
untuk konfigurasi codeigniter silakan diikuti :
– konfigurasi agar bisa terkoneksi ke database
– untuk folder dompdf yang didownload tadi silakan di replace sesuai degan folder yang telah tersedia.
Step ketiga
Buat controller Claporanpdf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Claporanpdf extends CI_Controller {
/*****
| Laporan PDF dengan DOMPDF
| controller claporanpdf
| by gtech
*****/
public function __construct() {
parent::__construct();
$this->load->model('mlaporan');
$this->load->library('dompdf_gen');
}
public function index()
{
$data['title'] = 'Laporan PDF CodeIgniter dengan DOMPdf'; //judul title
$data['qbarang'] = $this->mlaporan->getAllItem(); //query model semua barang
$this->load->view('vlaporan',$data);
}
// fungsi cetak pdf
public function cetakpdf(){
$data['title'] = 'Cetak PDF Barang'; //judul title
$data['qbarang'] = $this->mlaporan->getAllItem(); //query model semua barang
$this->load->view('vcetaklaporan', $data);
$paper_size = 'A4'; //paper size
$orientation = 'landscape'; //tipe format kertas
$html = $this->output->get_output();
$this->dompdf->set_paper($paper_size, $orientation);
//Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream("laporan.pdf", array('Attachment'=>0));
}
}
/* End of file claporanpdf.php */
/* Location: ./application/controllers/claporanpdf.php */
|
Catatan
pada controller claporanpdf pada fungsi cetakpdf telah disisipkan script dari library domp pdf agar file view vcetaklaporanpdf dirender ke format pdf, pada script fungsi streamnya terdapat tambahan Attachment =>0 ini berfungsi agar page tidak didownload langsung melainkan ditampilkan.
kemudian untuk model simpan dengan nama mlaporan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<?php
class Mlaporan extends CI_Model {
var $tabel = 'tb_barang';
function __construct() {
parent::__construct();
}
function getAllItem() {
$this->db->from($this->tabel);
$query = $this->db->get();
return $query->result();
}
}
?>
|
step keempat
untuk view yang pertama simpan dengan nama vlaporan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<!DOCTYPE html>
<html>
<head>
<title><?=$title?></title>
<style>
table{
border-collapse: collapse;
width: 70%;
margin: 0 auto;
}
table th{
border:1px solid #000;
padding: 3px;
font-weight: bold;
text-align: center;
}
table td{
border:1px solid #000;
padding: 3px;
vertical-align: top;
}
</style>
</head>
<body>
<p style="text-align: center">Tabel Barang</p>
<table>
<tr>
<th>No</th>
<th style="width: 20%">Nama Barang</th>
<th>Kategori</th>
<th>Harga</th>
<th>Stok</th>
<th>Satuan</th>
<th>Keterangan</th>
</tr>
<?php $no=0; foreach($qbarang as $rbarang){
$no++;
?>
<tr>
<td><?php echo $no;?></td>
<td><?php echo $rbarang->nama_brg;?></td>
<td><?php echo $rbarang->jenis;?></td>
<td><?php echo $rbarang->harga_brg;?></td>
<td><?php echo $rbarang->stok_brg;?></td>
<td><?php echo $rbarang->satuan;?></td>
<td><?php echo $rbarang->keterangan;?></td>
</tr>
<? }?>
</table>
<p style="text-align: center"><a href="<?php echo base_url()?>claporanpdf/cetakpdf">Cetak PDF</a> </p>
</body>
</html>
|
kemudia view yang kedua simpan dengan nama vcetaklaporan.php silakan buat scriptnya seperti dibawah ini
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
<!DOCTYPE html>
<html>
<head>
<title><?=$title?></title>
<style>
table{
border-collapse: collapse;
width: 100%;
margin: 0 auto;
}
table th{
border:1px solid #000;
padding: 3px;
font-weight: bold;
text-align: center;
}
table td{
border:1px solid #000;
padding: 3px;
vertical-align: top;
}
</style>
</head>
<body>
<p style="text-align: center">Tabel Barang</p>
<table>
<tr>
<th style="width: 2%">No</th>
<th style="width: 20%">Nama Barang</th>
<th>Kategori</th>
<th>Harga</th>
<th>Stok</th>
<th>Satuan</th>
<th>Keterangan</th>
</tr>
<?php $no=0; foreach($qbarang as $rbarang){
$no++;
?>
<tr>
<td><?php echo $no;?></td>
<td><?php echo $rbarang->nama_brg;?></td>
<td><?php echo $rbarang->jenis;?></td>
<td><?php echo $rbarang->harga_brg;?></td>
<td><?php echo $rbarang->stok_brg;?></td>
<td><?php echo $rbarang->satuan;?></td>
<td><?php echo $rbarang->keterangan;?></td>
</tr>
<? }?>
</table>
</body>
</html>
|
sekian tutorial kali ini untuk membuat report pdf
dan untuk mendapatkan referensi atau
tutorial pemrograman lengkap klik
disini
Tidak ada komentar:
Posting Komentar