How to Make PDF File Student Report in PHP

Generating pdf file with php

Website report using PHP program there are many reports formats like pdf, xls, doc, etc.  Among the reporting formats pdf is more populer than other format because the level of data security is pretty good. This discussion we will make a report student data in the PDF format, First we need FPDF class.

To create a student report we have to create a database where the data of students who will be called via the browser.


Create database : dbstudent
create table : data_students
CREATE TABLE `data_students` (
    `ID` varchar(13) NOT NULL,
    `name` varchar(50) NOT NULL,
    `program` varchar(50) NOT NULL,
    PRIMARY KEY (`nim`)
)    ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `data_students` (`id`, `name`, `program`) VALUES
('0410115261300', 'Jhony', 'Mechanical Engineering'),
('0410115261302', 'Huraiza Zaira', 'Industrial Engineering'),
('0410115261303', 'Fitriadi', 'Technical Information'),
('0410115261305', 'Anton', 'Industrial Engineering')


  
   
After we create a database and table above. Now we'll create a directory StudentReport. Put the FPDF class in the folder StudentReport and file std_report.php.

create std_report.php.
Open Notepad Application and type script below :

Open();
   $pdf->addPage();
   $pdf->setAutoPageBreak(false);
   $pdf->setFont('Arial','',12);
   $pdf->text(10,30,'Takasyma University');
   $pdf->text(10,36,'Students Data Information');
   $yi = 50;
   $ya = 44;
   $pdf->setFont('Arial','',9);
   $pdf->setFillColor(222,222,222);
   $pdf->setXY(10,$ya);
   $pdf->CELL(6,6,'Nu',1,0,'C',1);
   $pdf->CELL(25,6,'ID',1,0,'C',1);
   $pdf->CELL(50,6,'STUDENT NAME',1,0,'C',1);
   $pdf->CELL(50,6,'PROGRAM',1,0,'C',1);
   $ya = $yi + $row;
   $sql = mysql_query("select *from data_student order by nim");
   $i = 1;
   $no = 1;
   $max = 31;
   $row = 6;

while($data = mysql_fetch_array($sql)){
$pdf->setXY(10,$ya);
$pdf->setFont('arial','',9);
$pdf->setFillColor(255,255,255);
$pdf->cell(6,6,$no,1,0,'C',1);
$pdf->cell(25,6,$data[id],1,0,'L',1);
$pdf->cell(50,6,$data[name],1,0,'L',1);
$pdf->CELL(50,6,$data[program],1,0,'C',1);
$ya = $ya+$row;
$no++;
$i++;
$dm[kode] = $data[kdprog];
}
$pdf->text(100,$ya+6,"Jakarta, ".$tgl);
$pdf->text(100,$ya+18,"Cairo");
$pdf->output();
?>

 Good luck and for development you can do according to your individual creation.
Previous
Next Post »