Pages

Monday, October 17, 2011

How to create PDF from PHP


This posting will discuss about how to generate PDF files with pure PHP. It means generating pdf without using the PDFlib library. To do that we can use FPDF. F here stands for Free, we may use it for any kind of usage and modify it to suit our needs.
One of the advantage of FPDF is we don't need to enable any extension. Just include it in our code. It also works with PHP 4 and PHP 5. Below are the steps to use FPDF :
  1. Download the latest FPDF here
  2. Let's start with writing down Hello World. Here is the code
    require_once ('fpdf.php');
    
    $pdfObj = new FPDF();
    $pdfObj->AddPage();
    $pdfObj->SetFont('Tahoma','B',16);
    $pdfObj->Cell(90,10,'Hello World!');
    $pdfObj->Output();
    
  3. That's it. We have coded the introduction thing
  4. To get more tutorial, go to your fpdf directory > tutorial or go to online tutorial
  5. To get documentation of FPDF API, go to your fpdf directory > doc or go to online documentation

No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget