Tips Tricks Tutorials

WEB-NES-BAY

Learn Tips and tricks on Linux, Hacking, linux, PHP, Perl, Web, Hardware

bookmark bookmark
WEBNESBAY On July - 15 - 2009

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://www.fpdf.org/

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-&gt;Image(‘logo.png’,10,8,33);
//Verdana bold 15
//$this-&gt;SetFont(‘Verdana’,'B’,15);
//Move to the right
//$this-&gt;Cell(80);
//Adding Title
//$this-&gt;Cell(30,10,’This is the title’,1,0,’C');
//Line break
//$this-&gt;Ln(20);
}

//PDF footer
function Footer()
{
//Positioning 1.5 cm from bottom
$this-&gt;SetY(-15);
//Verdana italic 8
$this-&gt;SetFont(‘Verdana’,'I’,8);
//Page number
$this-&gt;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-&gt;setSourceFile(“mypdf.pdf”);

for ($i=1; $i &lt;= $pagecount; $i++) {

$tplidx = $pdf-&gt;ImportPage(1);

$pdf-&gt;addPage();
$pdf-&gt;useTemplate($tplidx,0,0,0);
}

$pdf-&gt;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:

  1. Generating PDF files with PHP and FPDF
  2. PHP Text Animation Tutorial And Example
  3. Solve: Cannot modify header information – headers already sent
  4. PHP Cookies tutorial a quick guide
Categories: PHP

Comments are closed.