Pages

Monday, October 25, 2010

FPDF

This article explains how you can create pdf documents in PHP. While I searched google for 'php + pdf', I found so many libraries that one can use. The one that looked simple to use was FPDF.

All you need to do is copy the php files that come along with the FPDF download and paste them in your php 'include' folder and refer to the package in your code.

This is a simple example.

<?php
require('fpdf.php');

$pdf=new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Cell(40,10,'Hello World!');
$pdf->Output();
?>

As shown in the example above, it is relatively simple to use the library. You can find the tutorials here.

You can create some complex pdfs such as the following,

A calender : Soruce Code Demo
A tree : Source Code Demo
Javascript support : Source Code Demo

You can find more such samples here. I hope you guys find it useful.

3 comments: