Generating PDF files with PHP

Generating PDF files with PHP

No site is completed with out pdf reports today and generating PDF reports with PHP is super easy. There are so many open source free libraries to tackle this job but I like FPDF class the best for its simplicity, size and ease of use.

Just head to the fpdf.org to download a free copy of the library. Unzip it in your web directory and include “fpdf.php” and that’s about it.

I am writing down a pretty basic code below to make use of fpdf.

 <?
require('fdpf/fpdf.php');
$ObjPdf = new FPDF();
$ObjPdf->AddPage();
$ObjPdf->SetTextColor(0,0,0);
$ObjPdf->SetFont('Arial',' B',16);
$ObjPdf->Cell(30,20,'Please generate the pdf for me..');
$ObjPdf->Output();
?>

Lets say you have save the code in your local webserver’s root directory with file name “pdf.php” and you have library in a folder named “fpdf”, then you’ll open pdf.php in your browser, it will generate a pdf file.

Happy experimenting.

Comments

Share

I am a web developer based in Lahore. I spend my days playing with wordpress, code igniter, wide variety of key web projects and frameworks.

Leave a Reply

Your email address will not be published. Required fields are marked *

12 + eighteen =

Translate »