In this article, we will learn how to generate PDF files and add new TrueType fonts with PHP by using FPDF. It is a free PHP class that contains many functions for creating and modifying PDFs. The FPDF class includes many features like page formats, page headers, footers, automatic page break, line break, image support, colors, links, and many more.
Approach:
Note: After downloading the FPDF class, make sure that the files “calligra.z” and “calligra.php” are in the same working directory where the PHP code is placed for generating the PDF file.
Example: The following example generates a PDF file with new calligraphy or fonts. The file can be downloaded or previewed as needed.
PHP
<?php
define( 'FPDF_FONTPATH' , './' );
require ( 'fpdf/fpdf.php' );
$pdf = new FPDF();
$pdf ->AddFont( 'Calligrapher' , '' , 'calligra.php' );
$pdf ->AddPage();
$pdf ->SetFont( 'Calligrapher' , '' ,35);
$pdf ->Cell(60,20, 'Hello GeeksforGeeks!' );
$pdf ->SetFont( 'Calligrapher' , '' ,72);
$pdf ->Cell(60,60, 'Its fun' );
$pdf ->Output();
?>
|
Output:

Add Calligraphy font
Advantage of using a new font in PDF: The advantage is that the PDF file is lighter. If the standard font is not available, a substitution font is used. It is always preferable to ensure that the required font is installed on the client systems. If the file is to be viewed by many people or a large audience, it is better to embed it.
Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
24 Aug, 2021
Like Article
Save Article