PWEB - B - Unduh Laporan PDF
Nama : Muhammad Amin
Link Repo
NRP : 5025201251
Kelas : PWEB - B - 2022
Langkah - langkah:
- Download library FPDF versi v1.85 (2022-11-10) pada link ini
- Buat sebuah folder baru dengan nama phpfpdf pada C:\xampp\htdocs\phpfpdf
- Extract file fpdf185.zip ke folder tersebut
- Buat file baru bernama "unduh-file.php" pada directory project
- Tambahkan script berikut pada file tersebut:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
require("../phpfpdf/fpdf.php"); | |
include "config.php"; | |
$pdf = new FPDF("l", "mm", "A4"); | |
$pdf->AddPage(); | |
$pdf->SetFont("Times", "B", 16); | |
$pdf->Cell(272, 7, "Daftar Calon Siswa Baru SMAN 1 Konoha Utara", 0, 1, "C"); | |
$pdf->Cell(272, 7, "", 0, 1, "C"); | |
$query = "SELECT * FROM calon_siswa"; | |
$result = mysqli_query($db, $query); | |
if ($result) { | |
$pdf->SetFont("Times", "B", 12); | |
$pdf->Cell(16, 6, "ID", 1, 0, "C"); | |
// $pdf->Cell(16, 6, "foto", 1, 0, "C"); | |
$pdf->Cell(64, 6, "Nama", 1, 0, "C"); | |
$pdf->Cell(64, 6, "Alamat", 1, 0, "C"); | |
$pdf->Cell(32, 6, "Jenis Kelamin", 1, 0, "C"); | |
$pdf->Cell(32, 6, "Agama", 1, 0, "C"); | |
$pdf->Cell(64, 6, "Sekolah Asal", 1, 1, "C"); | |
$pdf->SetFont("Times", "", 12); | |
while($siswa = mysqli_fetch_array($result)) { | |
$pdf->Cell(16, 6, $siswa["id"], 1, 0, "C"); | |
$pdf->Cell(64, 6, $siswa["nama"], 1, 0, "C"); | |
$pdf->Cell(64, 6, $siswa["alamat"], 1, 0, "C"); | |
$pdf->Cell(32, 6, $siswa["jenis_kelamin"], 1, 0, "C"); | |
$pdf->Cell(32, 6, $siswa["agama"], 1, 0, "C"); | |
$pdf->Cell(64, 6, $siswa["sekolah_asal"], 1, 1, "C"); | |
} | |
$pdf->Output('D', 'Daftar Calon Siswa Baru.pdf'); | |
} | |
else { | |
die("Gagal mengakses basis data..."); | |
} | |
?> |
Comments
Post a Comment