Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Creating a PDF using FPDF and PHP
// include composer packages
include "vendor/autoload.php";
// Create new Landscape PDF
$pdf = new FPDI('l');
// Reference the PDF you want to use (use relative path)
$pagecount = $pdf->setSourceFile( 'certificate.pdf' );
// Import the first page from the PDF and add to dynamic PDF
$tpl = $pdf->importPage(1);
// Use the imported page as the template
// Set the default font to use
// adding a Cell using:
// $pdf->Cell( $width, $height, $text, $border, $fill, $align);
// First box - the user's Name
$pdf->SetFontSize('30'); // set font size
$pdf->SetXY(10, 89); // set the position of the box
$pdf->Cell(0, 10, 'Niraj Shah', 1, 0, 'C'); // add the text, align to Center of cell
// add the reason for certificate
// note the reduction in font and different box position
$pdf->SetXY(80, 105);
$pdf->Cell(150, 10, 'creating an awesome tutorial', 1, 0, 'C');
// the day
$pdf->Cell(20, 10, date('d'), 1, 0, 'C');
// the month
$pdf->Cell(30, 10, date('M'), 1, 0, 'C');
// the year, aligned to Left
$pdf->Cell(20, 10, date('y'), 1, 0, 'L');
// render PDF to browser
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.