FPDF is a PHP class which allows to generate PDF files with pure PHP, that is to say without using the PDFlib library.
FPDF requires no extension (except zlib to activate compression and GD for GIF support). It works with PHP 4 and PHP 5 (the latest version requires at least PHP 4.3.10).
Using FPDF I will demonstrate hpw to add images and text. Firstly we need to download the library from the below mentioned URL’s
http://fpdi.setasign.de/index.php?p=home
Extract both packages in same folder and put the pdf in the same folder and name it as mypdf.pdf
Now we will create a script that will add text to pdf.
<?php
define(‘FPDF_FONTPATH’,'font/’);
require(‘fpdi.php’);
class PDF extends fpdi
{
//PDF Header
function Header()
{
//Logo
//$this->Image(‘logo.png’,10,8,33);
//Verdana bold 15
//$this->SetFont(‘Verdana’,'B’,15);
//Move to the right
//$this->Cell(80);
//Adding Title
//$this->Cell(30,10,’This is the title’,1,0,’C');
//Line break
//$this->Ln(20);
}
//PDF footer
function Footer()
{
//Positioning 1.5 cm from bottom
$this->SetY(-15);
//Verdana italic 8
$this->SetFont(‘Verdana’,'I’,8);
//Page number
$this->Cell(0,10,’This document was downloaded at ‘.date(“G:i T”, time()).’ on ‘.date(“l F jS Y”, time()).’. This document is only valid for 24 hours from this date.’,0,0,’C');
}
}
$pdf= new PDF();
$pagecount = $pdf->setSourceFile(“mypdf.pdf”);
for ($i=1; $i <= $pagecount; $i++) {
$tplidx = $pdf->ImportPage(1);
$pdf->addPage();
$pdf->useTemplate($tplidx,0,0,0);
}
$pdf->Output(“newpdf.pdf”,”I”);
?>
The above script is more easy and explanatory. You can refer more about the function in the URL http://www.fpdf.org/
Related posts:

