Your Ad Here

Dynamic PDF creation with PHP – Very Easy

November 22, 2007

FPDF is a PHP class which allows to create PDF files with PHP. The advantage is that PDFlib requires a fee for a commercial usage. F from FPDF stands for Free: So yu can use this class to generate PDFs for free and modify source code for your needs.

You must use this class if you want create PDF content directly from PHP to implement for example download of your site content in PDF dinamically. You can download it and see how it works in the sample code below.

Download FPDF

Sample PHP Script:
< ?php
require(‘fpdf.php’);

class PDF extends FPDF
{
function Header()
{
$this->Image(’logo.jpg’,10,10,190);
$this->SetFont(’Arial’,’B’,15);
$this->Cell(80);
$this->Ln(20);
}
}
$pdf=new PDF();
$pdf->AliasNbPages();
$pdf->AddPage();
$pdf->SetFont(’Helvetica’,”,12);
$pdf->Image(’../Images/photos/’.$line[’Code’].’.jpg’,56.8,119.9,103.6,72.5);
$pdf->Image(’../Images/clipart/’.$line[’Code’].’.jpg’,56.8,197.9,103.6,72.5);

$pdf->Ln(46);
$pdf->Cell(47);
$pdf->Cell(0,10,CODOEM.’: ‘.$line[’Description’],0,1);
$pdf->Cell(47);
$pdf->Cell(0,10,CODMA.’: ‘.$line[’Code’],0,1);
$pdf->Cell(47);
$pdf->Cell(0,10,BRAND.’: ‘.$line[’category’],0,1);
$pdf->Output();
?>

Related Post