Membuat nomor ujian dengan FPDF

Sateu acan kukurilingan milarian info di internet, ngadamel heula catetan membuat nomor ujian dengan menggunakan FPDF, secara konsep tidak jauh berbeda dengan catatan sebelumnya. Hanya penggunaan garis sebagai bingkai untuk pembatas. Adapun codenya sebagai berikut:

<?php
require (‘class.php’);

require (‘admin/config.php’);

require (‘fpdf.php’);

//db connection
//instance objek db
$db = new database();

//koneksi ke database
$db->konek();

if($_SERVER[“REQUEST_METHOD”] == “POST”){
if($_POST[‘nomor’]==””){
?>

alert(“Maaf Isi Nomor Pendaftaran Online dengan benar”);
document.location=”index.php”;

<?php
}
}
//ambil data
$nomor=$_POST[‘nomor’];

//mencari data
$cari = mysql_query(“SELECT * FROM hasiltertulis WHERE noDaftar = ‘$nomor'”);
$hasil = mysql_fetch_array($cari);

//nomor ujian
$id = $hasil[‘noPeserta’];
$nama = $hasil[‘nama’];

$asal = $hasil[‘asal’];

//begin extending class FPDF

class pdf extends FPDF{

//insert an image
function logo($gambar){
$this->Image($gambar, 5, 5, 10, 12);
}

//insert an image
function logo2($gambar){
$this->Image($gambar, 95, 4, 10, 12);
}
//header teks
function judul($teks1, $teks2, $teks3, $teks4, $teks5){
$this->Cell(49);
$this->SetFont(‘Times’,’B’,’6′);
$this->Cell(1,3,$teks1,0,1,’C’);
$this->Cell(49);
$this->Cell(1,3,$teks2,0,1,’C’);
$this->Cell(49);
$this->SetFont(‘Times’,’B’,’7′);
$this->Cell(1,3,$teks3,0,1,’C’);
$this->Cell(49);
$this->SetFont(‘Times’,”,’8′);
$this->Cell(1,3,$teks4,0,1,’C’);
$this->Cell(49);
$this->Cell(1,3,$teks5,0,1,’C’);
}
//line
function garis(){
$this->SetLineWidth(1);
$this->Line(5,21,103.5,21);
$this->SetLineWidth(0);
$this->Line(5,22,103.5,22);
}

function surat($hal){
$this->Ln(3);
$this->SetFont(‘Times’,’B’,7);
$this->Cell(98,5,$hal,0,1,’C’);
}
function biodata($id){
$this->SetFont(‘Times’,”,7);
$this->Ln(3);
$this->Cell(25);
$this->Cell(1,1,’Nomor Peserta’,0,0,’L’);
$this->Cell(25);
$this->Cell(1,1,’:’,0,0);
$this->Cell(2);
$this->Cell(1,1,$id,0,1);
}
function nama($nama){
$this->SetFont(‘Times’,”,7);
$this->Ln(3);
$this->Cell(25);
$this->Cell(1,1,’Nama’,0,0);
$this->Cell(25);
$this->Cell(1,1,’:’,0,0);
$this->Cell(2);
$this->Cell(1,1,$nama,0,1);
}
function foto($ket){
$this->SetFont(‘Times’,”,7);
$this->Cell(15,3,$ket,0,0,’C’);
}
function asal($asal){
$this->SetFont(‘Times’,”,7);
$this->Ln(3);
$this->Cell(25);
$this->Cell(1,1,’Asal Sekolah’,0,0);
$this->Cell(25);
$this->Cell(1,1,’:’,0,0);
$this->Cell(2);
$this->Cell(1,1,$asal,0,1);
}

function kepsek(){
$this->SetFont(‘Times’,”,7);
$this->Ln(5);
$this->Cell(70);
$this->Cell(0,3,’Pagar Alam, 12 April 2016′,0,1,’L’);
$this->Cell(70);
$this->Cell(0,3,’Kepala Sekolah,’,0,1,’L’);
}
function cap($tangan){
$this->Ln(5);
$this->Image($tangan,58,45,50,25);
}

function kepsek2(){
$this->Ln(5);
$this->Cell(70);
$this->SetFont(‘Times’,’B’,7);
$this->Cell(0,3,’SUNIAR, S.Pd, M.Pd’,0,1,’L’);
$this->SetFont(‘Times’,”,7);
$this->Cell(70);
$this->Cell(0,3,’Pembina,’,0,1,’L’);
$this->Cell(70);
$this->Cell(0,3,’NIP. 19720628 199802 1 001′,0,1,’L’);
}
function ctt($legal){
$this->Ln(5);
$this->SetFont(‘Times’,’I’,8);
$this->Cell(0,10,$legal,0,0,’L’);
}
}

//Instantisasi Objek

$pdf = new pdf();
//margin setting
$pdf->SetMargins(5,5,5);
$pdf->SetAutoPageBreak(true,5);
//adding page
$pdf->AddPage(‘P’,’A4′);
$pdf->Line(2,3,106,3);//horizontal
$pdf->Line(2,3,2,70);//vertical
$pdf->Line(106,3,106,70);//vertical
$pdf->Line(2,70,106,70);//horizontal

//bingkai vertical
$pdf->Line(5,25,5,45);//vertical
$pdf->Line(20,25,20,45);//vertical
$pdf->Line(5,25,20,25);//horizontal
$pdf->Line(5,45,20,45);//horizontal

//inserting path directory
$pdf->logo(‘images/pemkot.png’);
//inserting path directory
$pdf->logo2(‘images/sma-logo.png’);
//meletakkan judul disamping logo diatas
$pdf->judul(‘PEMERINTAH KOTA PAGAR ALAM’, ‘DINAS PENDIDIKAN’,’SEKOLAH MENENGAH ATAS NEGERI 1′,’UJIAN SARINGAN MASUK TERTULIS’, ‘TAHUN PELAJARAN 2016-2017’);
//membuat garis ganda tebal dan tipis
$pdf->garis();
//title
$pdf->surat(‘Nomor Peserta Ujian PPDB ‘);

//id
$pdf->biodata($id);
$pdf->foto(‘2 x 3’);
//nama
$pdf->nama($nama);

//asal sekolah
$pdf->asal($asal);
//tanda tangan
//tanda tangan kepsek
$pdf->kepsek();
$pdf->cap(‘images/ttd-cap.png’);
$pdf->kepsek2();

$date=date(“d-M-Y  h:i:s”);
$pdf->ctt(‘Printed on: ‘.$date.’ by ‘.$nama);

//output command
$pdf->output($nama.’.pdf’,’D’);

untuk source codenya dapat diunduh disini.

untuk pengaturan databasenya silahkan disesuaikan.

 

Tinggalkan Balasan

Please log in using one of these methods to post your comment:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s