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

2 Responses to “Dynamic PDF creation with PHP - Very Easy”

  1. FPDF is great, I use it to generate printable versions of purchase orders.
    It takes some time to get the hang of it, but once you know how to get things done you can really make some wonderfull stuf with it.

  2. Fantastic - I was looking for an alternative to pdflib, since I’m on a hosting provider that doesn’t yet have it built into PHP. I think this is going to give me everything I need to dynamically create .pdf documents without the need to have anything configured inside PHP.

Leave a Reply