Generate Report in PDF

Generate Report in PDF

Posted in : PHP Posted on : January 17, 2011 at 7:02 PM Comments : [ 0 ]

This section contains the detail about the Generating Report in PDF.

Generate Report in PDF

In this tutorial you will learn how to generate report  in PDF in a PHP web application . In this tutorial use two file :

  • registration.php
  • generate_report.php

In this tutorial "registration.php" use for enter data and  "generate_report.php" use for generate report in PDF. The code of "registration.php" given below :

<script type="text/javascript">
function validate(){ 

var username=document.getElementById("username").value;
var email=document.getElementById("email").value;
var password=document.getElementById("password").value;
var conf_password=document.getElementById("conf_password").value;
var address=document.getElementById("address").value;

if(username=="" || username.length<1){
alert("User Name field must not be blank.");
return false;
if(email=="" || email.length<1){
alert("Email field must not be blank.");
return false;
if(password=="" || password.length<1){
alert("Password field must not be blank.");
return false;

alert("Password and Confirm Password do not match.");
return false; 

if(address=="" || address.length<1){
alert("Address field must not be blank.");
return false;

return true; 
<body >
<h2 align="center" >Registration</h2>
<form action="generate_report.php" method="post"
onSubmit="return validate()" >
<table align="center" > 
<td>User Name :</td>
<td><input type="text" size="26" name="username" id="username" ></td>
<td>Email :</td>
<td><input type="text" size="26" name="email" id="email" ></td>
<td>Password :</td>
<td><input type="password" size="26" name="password" id="password" ></td>
<td>Confirm Password :</td>
<td><input type="password" size="26" name="conf_password" id="conf_password" ></td>
<td>Address :</td>
<td><textarea name="address" id="address" ></textarea></td>
<td><input type="submit" name="submit" value="Submit" /></td>

 The code of "generate_report.php" given below :



// cerate pdf
$pdf=new FPDF();

$pdf->Cell(35,10,'1.User Name : ',0,0);

$pdf->Cell(35,10,'2.Email : ',0,0);

$pdf->Cell(35,10,'3.Password : ',0,0);

$pdf->Cell(35,10,'4.Address : ',0,0);



In the "generate_report.php" first included the fpdf  library in our file and if  "isset($_POST['submit'])"  is true then access all  posted value and generate PDF.

Output :

When   "registration.php" file display output as :

Again if "User Name" field empty and click "Submit" button , display error message  as : 

and if email ,password , and Address field empty then display error message as :

and if password and confirm password not match display error message as :   

If all validation true in "registration.php" then form submit in "generate_report.php" and generate PDF that display as :

Download Source Code

Go to Topic «PreviousHomeNext»

Your Comment:

Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image

Tutorial Topics