FPDF is a PHP class that allows you to generate PDF files without using the PDFlib library.
FPDF is free and can be downloaded from the official website’s download section. The download package contains all necessary files, along with some tutorials on how to use it.
A basic example of using FPDF is with the following PHP code (you must download and extract the FPDF package in the folder where the PHP file with the code is located):
1
2
3
4
5
6
7
8
9
|
<?php
require('./fpdf.php');
$pdf=newFPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>
|
Let's say that you have downloaded and extracted the FPDF package inside a folder called ~/public_html/fpdf/. You can create a new PHP file called toPDF.php inside the same folder and insert the above code. You can then save the file and try to access it through your browser:
http://yourdomainname.com/fpdf/toPDF.php
Upon execution of the script, a new PDF file will be generated and you will be prompted to download it.