Create Event Certificates using PHP

Create Event Certificates using PHP

Earlier I have posted an article on create bulk PDF certificates using Python https://haneefputtur.com/creating-event-certificates-in-python.html. Since running python application is not very practical to newbies i have created this simple script which can be run using php and mysql if required.

Download Complete Source Code Here : https://github.com/haneefputtur/PHP_EVENT_Certificate

Let us have a basic version of certificate generation using php.

Example 1:

In this we will use one sample JPG file , add one line name and print as PDF.

Requirements

Create a JPG file as per below dimension

Make sure to leave the dynamic field name empty so we can fill using PHP.

We are going to use the PHP PDF from http://www.fpdf.org/.

Download the latest version of FPDF from this location : http://www.fpdf.org/en/download.php

https://github.com/haneefputtur/PHP_EVENT_Certificate/blob/main/Class1/basic.php
<?php
require('../fpdf/fpdf.php');

//$name = text to be added, $x= x cordinate, $y = y coordinate, $a = alignment , $f= Font Name, $t = Bold / Italic, $s = Font Size, $r = Red, $g = Green Font color, $b = Blue Font Color
function AddText($pdf, $text, $x, $y, $a, $f, $t, $s, $r, $g, $b) {
$pdf->SetFont($f,$t,$s);	
$pdf->SetXY($x,$y);
$pdf->SetTextColor($r,$g,$b);
$pdf->Cell(0,10,$text,0,0,$a);	
}

//$imgname = image file name , $x= x cordinate, $y = y coordinate
function AddImage($pdf, $imgname, $x, $y) {

$pdf->Image($imgname,$x,$y,0);	

}

//Create A 4 Landscape page
$pdf = new FPDF('L','mm','A4');
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->SetCreator('Haneef Puttur');
// Add background image for PDF
AddImage($pdf,'../template.jpg', 0,0);


//Add a Name to the certificate

AddText($pdf,ucwords('Mahammad Haneef'), 0,80, 'C', 'Helvetica','B',30,3,84,156);

$pdf->Output();
?>

In this tutorial we have created a basic PDF certificate using FPDF. In the next sessions we will explore dynamic options for bulk creation

Download Complete Source Code Here : https://github.com/haneefputtur/PHP_EVENT_Certificate

As an extended version I have added Multi Page feature.

Here I have created a function which can be called by one line. Each line will create a new PDF page.

Source code : https://github.com/haneefputtur/PHP_EVENT_Certificate/blob/main/Class1/MulitPage.php