Tugas 10 Pemrograman Web C: Latihan Membuat PDF
index.php:
1: <?php include("koneksi.php"); ?>
2: <!DOCTYPE html>
3: <html>
4: <head>
5: <title>List Mahasiswa Institut Teknologi Sumeru</title>
6: <link rel="stylesheet" href="styles.css">
7: <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Raleway">
8: <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Poppins">
9: </head>
10: <body>
11: <div class="container">
12: <header>
13: <h2>INSTITUT TEKNOLOGI SUMERU</h2>
14: <h3>DAFTAR MAHASISWA DEPARTEMEN SISTEM GACHA</h3>
15: </header>
16: <br>
17: <table border="1" style="margin-left:auto;margin-right:auto;">
18: <thead>
19: <tr>
20: <th>NIM</th>
21: <th>NAMA MAHASISWA</th>
22: <th>NO HP</th>
23: <th>TANGGAL LAHIR</th>
24: </tr>
25: </thead>
26: <tbody style="text-align: left;">
27: <?php
28: $sql = "SELECT * FROM mahasiswa";
29: $query = mysqli_query($db, $sql);
30: while($mahasiswa = mysqli_fetch_array($query)){
31: echo "<tr>";
32: echo "<td>".$mahasiswa['nim']."</td>";
33: echo "<td>".$mahasiswa['nama_lengkap']."</td>";
34: echo "<td>".$mahasiswa['no_hp']."</td>";
35: echo "<td>".$mahasiswa['tanggal_lahir']."</td>";
36: echo "</tr>";
37: }
38: ?>
39: </tbody>
40: </table>
41: <p>Total: <?php echo mysqli_num_rows($query) ?></p>
42: <form action="proses-pdf.php" method="POST">
43: <input type="submit" value="Membuat Laporan PDF" name="buat">
44: </form>
45: </div>
46: </body>
47: </html>
koneksi.php:
1: <?php
2: $server = "sql305.byethost24.com";
3: $user = "b24_32977667";
4: $password = "000webhostampas";
5: $nama_database = "b24_32977667_tutorial";
6: $db = mysqli_connect($server, $user, $password, $nama_database);
7: if( !$db ){
8: die("Gagal terhubung dengan database: " . mysqli_connect_error());
9: }
10: ?>
proses-pdf.php:
1: <?php
2: require('fpdf.php');
3: if(isset($_POST['buat'])){
4: $pdf = new FPDF('l','mm','A5');
5: $pdf->AddPage();
6: $pdf->SetFont('Arial','B',16);
7: $pdf->Cell(190,7,'INSTITUT TEKNOLOGI SUMERU',0,1,'C');
8: $pdf->SetFont('Arial','B',12);
9: $pdf->Cell(190,7,'DAFTAR MAHASISWA DEPARTEMEN SISTEM GACHA',0,1,'C');
10: $pdf->Cell(10,7,'',0,1);
11: $pdf->SetFont('Arial','B',10);
12: $pdf->Cell(20,6,'NIM',1,0);
13: $pdf->Cell(85,6,'NAMA MAHASISWA',1,0);
14: $pdf->Cell(30,6,'NO HP',1,0);
15: $pdf->Cell(35,6,'TANGGAL LAHIR',1,1);
16: $pdf->SetFont('Arial','',10);
17: include('koneksi.php');
18: $mahasiswa = mysqli_query($db, "select * from mahasiswa");
19: if($mahasiswa) {
20: while ($row = mysqli_fetch_array($mahasiswa)){
21: $pdf->Cell(20,6,$row['nim'],1,0);
22: $pdf->Cell(85,6,$row['nama_lengkap'],1,0);
23: $pdf->Cell(30,6,$row['no_hp'],1,0);
24: $pdf->Cell(35,6,$row['tanggal_lahir'],1,1);
25: }
26: }
27: else {
28: die("Gagal mengakses tabel...");
29: }
30: $pdf->Output('D', 'report.pdf');
31: }
32: else {
33: die("Pembuatan file laporan PDF gagal...");
34: }
35: ?>
styles.css:
1: :root {
2: --container-background: white;
3: --button-background: rgba(32, 191, 212, 0.5);
4: --button-background-hover: rgba(32, 191, 212, 1);
5: --text: black;
6: }
7: * {
8: box-sizing: border-box;
9: font-family: 'Poppins', sans-serif;
10: color: var(--text);
11: }
12: h1, h2 {
13: font-family: 'Raleway', sans-serif;
14: }
15: table {
16: margin-left: auto;
17: margin-right: auto;
18: }
19: tbody {
20: text-align: left;
21: }
22: input[type="submit"] {
23: padding: 8px 15px;
24: background-color: var(--button-background);
25: border-radius: 8px;
26: border-style: none;
27: transition: 0.15s;
28: }
29: input[type="submit"]:hover {
30: background-color: var(--button-background-hover);
31: color: var(--container-background);
32: cursor: pointer;
33: }
34: .container {
35: max-width: 1080px;
36: margin: 80px auto;
37: text-align: center;
38: }
Link Repository: https://github.com/brianakbar/Tugas10_PWebC_LatihanPembuatanPDF
Link Website: http://membuatpdf.nichesite.org/index.php
Screenshot:
Comments
Post a Comment