PHP PDF Generation using FPDF
Posted By : Vikas Verma | 31-Jul-2019
FPDF class of PHP which helps us to generate PDF files with PHP code and that is to say without using the PDFlib library. It is free to use and it's independent of any API keys. FPDF stands for Free PDF.
The main features of this class are:
Allows to setup page format and margins.
Allows to setup page header and footer.
It provides an automatic page break and a line break.
It supports images in various formats (JPEG, PNG, and GIF).
It allows us to setup Colors and Links.
It also supports encoding.
It also supports the Page compression feature and provides many other functions.
FPDF is extension independent except Zlib to enable compression and GD for GIF support and requires at least PHP 5.1 to run this. A section of the script is also there to support useful extensions to work such as bookmarks, rotations, tables, barcodes.
There are no limits in regarding the document size but still, there are some constraints, however:
- there's typically a maximum memory size allotted to PHP scripts.
For very huge documents, especially with images, the limit may be reached (the file being built-in memory).
The parameter is configured in the php.ini file.
- the utmost execution time allotted to scripts defaults to thirty seconds. This limit can, of course, be easily reached.
It can be configured by some changes in php.ini and may be changed dynamically with set_time_limit() function.
What languages can I use?
Central European, Cyrillic, Greek, Baltic, and Thai, provided you own TrueType or Type1 fonts with
the desired character set. It supports UTF-8.
Let's make our first"Hello World" example.
AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
Now let’s see that code line by line,
require('fpdf.php');
$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',24);
$pdf->Cell(30,15,'Hello World!');
$pdf->Output();
Cookies are important to the proper functioning of a site. To improve your experience, we use cookies to remember log-in details and provide secure log-in, collect statistics to optimize site functionality, and deliver content tailored to your interests. Click Agree and Proceed to accept cookies and go directly to the site or click on View Cookie Settings to see detailed descriptions of the types of cookies and choose whether to accept certain cookies while on the site.
About Author
Vikas Verma
He is frontend developer. He is a learner by heart and has a passion and profile to adapt various technologies.