Yang terpenting dalam membuat report Php dalam bentuk Pdf adalah anda harus download file FPDF kemudian ekstrak dan simpan menjadi satu folder dengan halaman index
.
File fpdf dapat di download disini Kemudian copy Cource code dibawah ini.
<?php
//koneksi ke database
include ("koneksi.php");
$query = "SELECT * FROM pegawai ORDER BY nip ";
$sql = mysql_query ($query);
$data = array();
while ($row = mysql_fetch_assoc($sql)) {
array_push($data, $row);
}
// setting laporan
$judul = "Laporan Data Pegawai";
$alamat= "Jln.Geong no.50";
$header = array(
array("label"=>"nip", "length"=>30, "align"=>"L"),
array("label"=>"nama", "length"=>30, "align"=>"L"),
array("label"=>"tgllahir", "length"=>30, "align"=>"L"),
array("label"=>"kode_post", "length"=>30, "align"=>"L"),
array("label"=>"alamat", "length"=>30, "align"=>"L"),
array("label"=>"Nama_Foto", "length"=>30, "align"=>"L"),
);
//sertakan library FPDF dan bentuk objek
require("fpdf.php");//directory file
$pdf = new FPDF();
$pdf->AddPage();
//tampilkan judul laporan
$pdf->SetFont('Arial','B','16');
$pdf->Cell(0,20, $judul, '0', 1, 'C');
//tampilkan judul laporan
$pdf->SetFont('Arial','B','10');
$pdf->Cell(30,22, $alamat, '0', 1, 'B');
//buat header tabel
$pdf->SetFont('Arial','','8');
$pdf->SetFillColor(255,0,0);
$pdf->SetTextColor(255);
$pdf->SetDrawColor(128,0,0);
foreach ($header as $kolom) {
$pdf->Cell($kolom['length'], 5, $kolom['label'], 1, '0',
$kolom['align'], true);
}
$pdf->Ln();
//tampilkan data tabelnya
$pdf->SetFillColor(224,235,255);
$pdf->SetTextColor(0);
$pdf->SetFont('');
$fill=false;
foreach ($data as $baris) {
$i = 0;
foreach ($baris as $cell) {
$pdf->Cell($header[$i]['length'], 5 , $cell , 1, '0',
$kolom['align'],true);
// $i++;
}
$fill = !$fill;
$pdf->Ln();
}
//output file PDF
$pdf->Output();
?>
Kemudin save dengan nama report.php
note : script dapat diedit sesuai kebutuhan...
Output
![]() |
| Add caption |

1 komentar:
kok file didalam FPDF banyak....dan ekstensinya(.html) semua yang di pakek yang mana..??
Posting Komentar