How to generate dynamic Certificate in PHP using FPDF
- Tech Area
- March 1, 2023
In this tutorial, we discuss how to generate dynamic certificate in PHP. To generate dynamic certificate you have to download FPDF. FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library.
Below are the step by step process of how to generate certificate in PHP using FPDF.
Step 1: Click on below link to download FPDF
Step 2: Design a certificate in .jpg/.jpeg format
Step 3: Download any suitable font file for certificate
In this step, download ‘Calibri_Regular’ font file.
Step 4: Create a folder to store dynamically generated certificate
In this step, create folder name ‘download-certificate’ to store dynamically generated certificate.
Step 5: Create index.php
In this step, create a new file index.php. This is the main file used to generate certificate.
index.php
<?php
require("fpdf/fpdf.php");
header('content-type:image/jpeg');
$font = "E:/xampp/htdocs/ecertificate/Calibri_Regular.ttf";
$time = time();
$image = imagecreatefromjpeg("Certificate.jpg");
$color = imagecolorallocate($image,19,21,22);
$name = "oliver sam";
imagettftext($image,90,0,690,800,$color,$font,$name);
//(size,angel,left-right,up-down)
imagejpeg($image,"download-certificate/$time.jpg");
imagedestroy($image);
$pdf = new FPDF();
$pdf->AddPage();
$pdf->Image("download-certificate/$time.jpg",0,0,210,148);
ob_end_clean();
$pdf->Output();
?>
After successfully follow all the step, you will find like this.
Step 6: Run the Program
Run the program using the URL: http://localhost/ecertificate/
Join 10,000+ subscriber