03-Apr-2023
.
Admin
Hi guys,
Today i will explained How To Generate a pdf file in user data in php. This example is so easy to use in php. This example to i am perform to the generate user data through a pdf file.
This example to create a few other file to use. I am use to the fpdf generater in php to use in generate pdf file in php.
So let's start to the example.
Example :
Fpdf zip Dowload Link
I am add to the Fpdf file dowload link.Fpdf link
form.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Pdf Generate Form</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js"></script>
<style>
.login-form {
width: 340px;
margin: 50px auto;
font-size: 15px;
}
.login-form form {
margin-bottom: 15px;
background: #f7f7f7;
box-shadow: 0px 2px 2px rgba(0, 0, 0, 0.3);
padding: 30px;
}
.login-form h2 {
margin: 0 0 15px;
}
.form-control, .btn {
min-height: 38px;
border-radius: 2px;
}
.btn {
font-size: 15px;
font-weight: bold;
}
</style>
</head>
<body>
<div class="login-form">
<form name="frmUser" method="post" action="pdf.php" align="center">
<h2 class="text-center">Pdf Generate Form</h2>
<div class="message text-danger"><?php if($message!="") { echo $message; } ?></div>
<div class="form-group">
<input type="text" autocomplete="off" class="form-control" placeholder="Roll No" name="rollno">
</div>
<div class="form-group">
<input type="text" class="form-control" name="firstname" placeholder="First Name" autocomplete="off">
</div>
<div class="form-group">
<input type="text" class="form-control" name="lastname" placeholder="Last Name" autocomplete="off">
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" placeholder="email" autocomplete="off">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary btn-block" value="Submit">Submit</button>
</div>
</form>
</div>
</body>
</html>
pdf.php
<?php
$rollno = $_POST['rollno'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
require("fpdf/fpdf.php");
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('arial','',12);
$pdf->Cell(0,10,"Registration Details",1,1,'C');
$pdf->Cell(20,10,"Roll No",1,0);
$pdf->Cell(45,10,"First Name",1,0);
$pdf->Cell(45,10,"Last Name",1,0);
$pdf->Cell(0,10,"Email",1,1);
$pdf->Cell(20,10,$rollno,1,0);
$pdf->Cell(45,10,$firstname,1,0);
$pdf->Cell(45,10,$lastname,1,0);
$pdf->Cell(0,10,$email,1,0);
$file = time().'.pdf';
$pdf->output($file,'D');
?>
now you can check your own.
i hope it can help you...
#PHP 8
#PHP